0

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

0

2 Answers 2

0

try this...

replace twentyfourteen_paging_nav();

with

global $wp_query;
$temp_query = $wp_query;
$wp_query   = NULL;
$wp_query   = $loop;
twentyfourteen_paging_nav();
$wp_query = NULL;
$wp_query = $temp_query;
0

I see this issue all too often. You should never need to run your own query on an archive page. Not only does it introduce unnecessary load on the server, you confuse the hell out of WordPress as it's no longer aware of how/what exactly you're querying.

Instead, tweak the main query to suit your needs and stick to while ( have_posts() ):

function wpse_177068_videos_per_page( $wp_query ) {
    if ( $wp_query->is_main_query() && $wp_query->is_tax( 'video_category_categorie', 3 ) ) {
        $wp_query->set( 'posts_per_page', 2 );
    }
}

add_action( 'pre_get_posts', 'wpse_177068_videos_per_page' );

Add this hook to your functions.php.

Not the answer you're looking for? Browse other questions tagged or ask your own question.