0

I have an Index.php with a basic loop with this query before:

<?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
      'category_name' => 'work',
      'orderby' => 'asc',
      'paged' => $paged
    );
    query_posts($args); 
?>

Which works. But when I count the amount of pages using max_num_pages it says there are 5 pages worth of posts in the 'category_name' => 'work' but I know that there are not and whats happening is its including the other posts outside of this category.

How do I stop that from happening and get the loop to just display the actual amount of pages containing posts categorised with 'work' only?

  • Something like this? function vs_pre_get_posts( $query ) { if ( is_home() && $query->is_main_query() ) { $query->set( 'category__not_in', array( 13 ) ); } } add_action( 'pre_get_posts', 'vs_pre_get_posts' ); – Victor Jan 26 '14 at 19:43
0

query_posts() should not be used in general and especially when dealing with pagination.

You need to be making adjustments before template is reached, usually via hook, on which there is plenty of material on site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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