• Resolved mkubilayk

    (@mkubilayk)


    I am excluding posts from some specific categories on frontpage by using the following code in The Loop (continue to the next post if $flag is false):

    foreach ((get_the_category()) as $category)
    	if($category->cat_ID == 3 || $category->cat_ID == 4) {
    		$flag = false;
    		break;
    	}

    This is successful as a solution to exclude posts from cat3 and cat4. However post count per page is incremented while going through those excluded ones. That’s why number of posts shown on the page is not equal to what is set in the Admin Panel.

    Is there a way that I could decrement the post count by one for those I skip? or any other way to retain the same amount of posts per page?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You need to exclude the categories in the query, not afterward. Add the parameter to the query to exclude those categories.

    Exactly how you code this depends on the way that your query_posts(), if there is one, is set up.

    Post a few (<10) lines of code showing the query_posts() call and you may get more specific help. Or, if there is no query_posts() call, show the start of the Loop.

    Thread Starter mkubilayk

    (@mkubilayk)

    I was worried about page navigation problems however it looks defect-free so far. Here is the structure:

    $my_query = new WP_Query( array('category__not_in' => array( 3, 4, 44 ) , 'paged' => get_query_var('paged')))
    
    while ($my_query->have_posts()) {
    	$my_query->the_post();
    	...
    	...
    }
    
    wp_pagenavi(array('query' => $my_query));
    wp_reset_postdata();	// avoid errors further down the page

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Post per Page Counter Problem (Excluded Categories)’ is closed to new replies.