Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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

Codex: WP_Query - Category Parameters

share|improve this answer
    
Would I just use the variable $blog_cat or how will I make it run through all of the array? –  Brainbuzz media Nov 8 '11 at 13:42
    
Yes, you would just use the variable if it is an array. –  Kevin Langley Jr. Nov 8 '11 at 13:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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