0

I'm trying to put a variable inside a wp_query but I can't get it to work. What am I doing wrong?

$stuff = array('easy','medium','hard');

$loop = new WP_Query('category='.$stuff.'&order=asc');

while($loop->have_posts()): $loop->the_post(); ?>

I tried this but it doesn't work:

$stuff = array(
'cat' => array('easy', 'medium', 'hard'),
'orderby' => 'title',
'posts_per_page' => '-1'
);

$loop = new WP_Query($stuff);

Thanks.

1
  • You are trying to concatenate an array ($stuff) in middle of your string... Commented Oct 10, 2011 at 20:55

1 Answer 1

1

'cat' is for cat id's try:

$query = new WP_Query( 'category_name=staff,news' );

or

$query = new WP_Query( array( 'category__in' => array( 2, 6 ) ) );

read this:

http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

Sign up to request clarification or add additional context in comments.

1 Comment

Didn't you want category__in?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.