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

  • Home
  • SEARCH
  • 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 1096319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:15:59+00:00 2026-05-17T00:15:59+00:00

I am working on a wordpress theme and need to select posts that are

  • 0

I am working on a wordpress theme and need to select posts that are in multiple categories to build a menu. I could set it up to work off of the tags, or a combination of tags and categories, but in the end I need to be able to search by multiple cat/tag. The only built-in wordpress function that I have been able to find that allows for a multiple AND search on cat/tag is the query_posts function as such:

query_posts(array('category__and' => array(list_of_cats)))

There are two problems with that. The first is that the wp docs say not to use it. The second is a real problem in that I need to know how many posts were queried before running my loop since I don’t want to build submenus that are empty or only have one or two items in them.

The alternative is to run my own query but I can’t quite figure out the right statement to run to find posts in the selected categories. I can visualize what needs to happen to search for two categories, but it gets fuzzy at 3+.

I can execute multiple, independent queries and then use array_intersect to find the those that match all queries but I would like to expand my mysql and/or wp knowledge a bit here.

In summary, I would appreciate an answer to any one of the following questions:

1 – an alternative to query_posts() that allows for multiple AND matching
2 – a way to find the number of posts that will be looped when using query_posts()
3 – some mysql magic that runs a big union on multiple queries to the same table

Thanks in advance

  • 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-17T00:15:59+00:00Added an answer on May 17, 2026 at 12:15 am

    “If you want to create separate Loops outside of the main one, you should use get_posts() instead.

    Note: Beginning with Version 3.0, an array of Page ID also can be used for the include and exclude parameters.”

    Pretty sure you can do something like:

    $wp_query->post_count
    

    To get the total number of queried posts.

    Yeah, according to WPQuery:

    get_posts()
    Fetch and return the requested posts
    from the database. Also populate
    $posts and $post_count.

    🙂

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

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would advise against using the backspace key, since that… May 17, 2026 at 9:02 am
  • Editorial Team
    Editorial Team added an answer (Note: I'll assume that by "decode and dispatch" you mean… May 17, 2026 at 9:02 am
  • Editorial Team
    Editorial Team added an answer Non static properties (alias fields, alias member variables) have their… May 17, 2026 at 9:01 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm working on a wordpress theme, and I have a rather unique structure that
I'm working on a wordpress theme that uses dropdowns for part of the site
I'm working on a WordPress site that uses a dynamically generated menu system which
I'm working on a WordPress template and need to add a hyperlink to the
I'm working on delving into more complex WordPress theme options pages. Right now, I
Is there anything need to enable for shortcode to work in Wordpress 3.0? I
I'm working on a WordPress that will allow the site administrator to switch between
I'm working on a custom wordpress theme with a little bit of backend admin
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a somewhat complex page for configuring customers at work. The setup is

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.