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
get_posts
accepts any of the arguments that WP_Query accepts. So there’s a few options.1.
meta_key
andmeta_value
2.
meta_query
meta_query
is more sophisticated that usingmeta_key
andmeta_value
. For instance, say you wanted to get posts that have the meta_key with one of three values:There’s a ton of examples for you to checkout in the custom fields section of
WP_Query
‘s documentation.Yes. Its possible. Use
meta_key
andmeta_value
parameters.meta_key
is for custom field key (e.g. location) andmeta_value
is for custom field value (e.g. berkshire).Use the refined code below: