I am using get posts, but I need to refine the query based on posts where a certain meta_key has a certain value.

Something like this

<?php $reviews = get_posts('post_type=reviews&numberposts=-1&   // eg. // location=berkshire');

Is it possible to do this and if so how?

Marvellous

link|improve this question
feedback

1 Answer

Yes. Its possible. Use meta_key and meta_value parameters. meta_key is for custom field key (e.g. location) and meta_value is for custom field value (e.g. berkshire).

Use the refined code below:

/* Query args. */
$args = array(
    'post_type' => 'reviews',
    'posts_per_page' => -1,
    'meta_key' => 'location', 
    'meta_value' => 'berkshire'
);

/* Get Reviews */
$reviews = get_posts( $args );
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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