Custom Post Type and Taxonomy pagination 404 error

前端 未结 2 1262
-上瘾入骨i
-上瘾入骨i 2021-01-26 05:12

Pagination is not working on taxonomy.php. Here is my code for register custom post type and taxonomy

add_action(\'init\', \'ep_add_equipment\');
function ep_add         


        
相关标签:
2条回答
  • 2021-01-26 05:26
    // get the global query object
    global $wp_query;
    // get the correct page var
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    // create the page argument
    $args=  array('paged'=> $paged);
    // merge the page argument array with the original query array
    $args = array_merge( $wp_query->query, array( 'post_type' => 'equipment' ) );
    // Re-run the query with the new arguments
    query_posts( $args );
    
    0 讨论(0)
  • 2021-01-26 05:47

    May be you need to enable search to enable pagination

    While declaring custom taxonomy you should disable search excluding.

    exclude_from_search => false

    This fixed my problem. I have very hard time to find this solution. Hope this helps everyone.

    My code is:

    register_post_type( 'lifestyle',
                    array( 
                    'label' => __('Lifestyle', 'tmi'), 
                    'public' => true, 
                    'show_ui' => true,
                    'show_in_nav_menus' => true,
                    'rewrite' => true,
                    'hierarchical' => true,
                    'menu_position' => 5,
                    'exclude_from_search' =>false,
                    'supports' => array(
                                         'title',
                                         'editor',
                                         'thumbnail',
                                         'excerpt',
                                         'revisions')
                        ) 
                    );
    
        register_taxonomy('lifestylecat', __('lifestyle', 'tmi'),array('hierarchical' => true, 'label' =>  __('Categories', 'tmi'), 'singular_name' => __('Category', 'tmi'))
        );
    
    0 讨论(0)
提交回复
热议问题