Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6388805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:19:30+00:00 2026-05-25T03:19:30+00:00

So I am excluding posts is several categories from a blog page (categories 4-11).

  • 0

So I am excluding posts is several categories from a blog page (categories 4-11).

I am doing so using the following code:

if (have_posts()) : while (have_posts())  : the_post(); 
    $category = get_the_category();


     if($category[0]->cat_ID > 11 || $category[0]->cat_ID < 4){
        continue;
     }

This works to exclude the categories posts from the page but it does not retain the post count per page being 10 or whatever it is set to in the Admin.

How would I programatically decrement the post count by one for posts I skip in the WordPress Loop so I exclude the category posts i do not want but also retain the same amount of posts per page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:19:31+00:00Added an answer on May 25, 2026 at 3:19 am

    The easiest (but not most efficient) way to do this is to replace the global $wp_query by a custom query using category__in…

    global $wp_query;
    $wp_query = new WP_Query(array("category__in"=>array(4,5,6,7,8,9,10,11)));
    

    …then do the loop…

    while (have_posts()){
         the_post();
    
         //etc..
    }
    

    This will make the paging accurate, and you can rely on the high-level templating functions like next_posts_link().

    Probably a more efficient way (that doesn’t throw out and replace $wp_query) would be to mess with the original query before it’s executed…

     add_action('parse_query', 'my_parse_query');
     function my_parse_query(&$q){
          //decide if you want to mess with the query....
          //if not, return
          $q->set_query_var("category__in", array(4,5,6,7,8,9,10,11));
     }
    

    my_parse_query would be called on every query, including those for pages and single posts, so you would have to add some logic to the function to only add category__in where it made sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code has been created from a different post, but I now have
i am using the following code for form action, // includes require_once('inc/mysql_wrapper.php'); $DB=get_db_connection(); require_once('inc/defines.inc.php');
I want to generate random numbers from -n to n excluding 0. Can someone
I want to combine two array's, excluding duplicates. I am using a custom class:
I'm trying to select from table, excluding where id is something, say 7. I
I have the following code: <select name=to class=combo value=' <?php if(isset($_POST['reply'])) { echo <option
The Facebook connect code is eluding me a bit. I have no problem doing
So I just tried excluding String[] args from the main method It compiled alright
Every reference to excluding properties from Grails scaffolded views revolves around adding them to
Take these stats from a post from the App Engine blog as an example:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.