Dave O'Dwyer
Dave O'Dwyer

Reputation: 1192

Custom Wordpress query using WP_Query()

I'm trying to get a custom query going in wordpress. Basically, I want to select all custom post types where the variable "name" has been set to "sean".

I have tried the following :

$my_loop = new WP_Query( array( 'post_type' => 'my_post', 'meta_value=sean',
'posts_per_page' => 15, 'orderby' => 'id', 'order' => 'DESC' ) );

I got this from the wordpress codex : Display posts where the custom field value is 'blue', regardless of the custom field key:

$query = new WP_Query( 'meta_value=blue' );

Any Help would be appreciated

EDIT: I should add that I do indeed have a wordpress loop using :

   while ( $my_loop->have_posts() ) {
   $pdf_loop->the_post();.... etc

Thanks again,

Dave

Upvotes: 1

Views: 1316

Answers (1)

Richard M
Richard M

Reputation: 14535

You are mixing query string and array style arguments. Try either

new WP_Query(array(
    'post_type' => 'my_post', 
    'meta_value' => 'sean',
    'posts_per_page' => 15,
    'orderby' => 'id',
    'order' => 'DESC'
));

Or

new WP_Query('post_type=my_post&meta_value=sean&posts_per_page=15&orderby=id&order=DESC');

Upvotes: 2

Related Questions