I have a theme options panel that the user can set which categories they want to use which is then saved as an array $blog_cat[0] etc. They can select as many categories as they want for the array and it saves the category number not slug.

I am having trouble when I go to make a wp_query using these settings. How can I take that array and use it in the wp_query?

If I use the following bit of code it will output all of the categories: $catnum = 0; foreach($blog_cat as $blogcats) {echo $blog_cat[$catnum]; $catnum++;}

However, I can't use this in the actual wp_query which looks like this:

$wp_query = new WP_Query('category_name=' . $blog_cat . '&showposts=3');

I can target them individually but not dynamically regardless of how many are set.

I'm guessing this isn't a very hard problem to fix but I don't know enough about the syntax to figure out how.

1 Answer 1


You can use the category__in parameter and that will do exactly what you're looking for.

Codex: WP_Query - Category Parameters

  • Would I just use the variable $blog_cat or how will I make it run through all of the array? Nov 8, 2011 at 13:42
  • Yes, you would just use the variable if it is an array. Nov 8, 2011 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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