user4373589
user4373589

Reputation:

Pagination fault in custom post type archive page

I create ad custom post type register_post_type( 'videos', $args); and custom taxonomy for that register_taxonomy( 'video_category_categorie', 'videos', $args ); Maximum number of post displayed is 2 per page. Via word press backend in archive-videos. php i write the for displaying the post from a specific taxonomy ( taxonomy item id is 3 ) $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$args = array( 'post_type' => 'videos','paged' => $paged,'tax_query' => array(
    array(
    'taxonomy' => 'video_category_categorie',
    'field' => 'term_id',
    'terms' => 3)
));

$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo get_the_title().'<br>';
endwhile;
twentyfourteen_paging_nav();

Now i get the result correctly only pst from taxonomy id 3 is displayed. But the pagination is not correct. it showing 1 2 3 4 . actually there is 5 post that is in taxonomy id 3 . so the correct pagination is 1 2 3 .

And also when clicking 4 page the page didn’t show any post name .

Please help

Upvotes: 1

Views: 392

Answers (1)

cpilko
cpilko

Reputation: 11852

If you look at the source for twentyfourteen_paging_nav(), you'll see it acts upon the $GLOBALS['wp_query'], not on your custom loop query.

If you want to keep using twentyfourteen_paging_nav(), you need to use the standard loop, and modify query_posts to alter the global wp_query object instead of your $loop, which is a separate instance of WP_Query.

In your case, that would mean changing the line:

$loop = new WP_Query( $args );

to:

query_posts ( $args );

and removing $loop-> from the rest of your code.

If you can't do that for any reason, you'll need to switch to another Wordpress pagination function

Upvotes: 1

Related Questions