Basically meta_query parameter of WP_Query allows you to search WordPress posts / pages / custom post types by their meta data and sort the result.
In this post I assume that you already have basic knowledge how to work with WP_Query class in WordPress. Before I begin, I want to show you some very simple examples. The similar examples you can find in WordPress Codex.
As you know all the posts have the metadata you can populate in “Custom fields” metabox (the metabox by the way can be hidden). So, for example, if you want to get a post with meta key show_on_homepage and meta value on, you can do it the following way:
$rd_args = array(
'meta_key' => 'show_on_homepage',
'meta_value' => 'on'
);
$rd_query = new WP_Query( $rd_args );
- Query Posts by a Meta Value
The simple example below allows you to get all the posts with a specific custom field value. Let’s just get all the posts with custom field name “color” and custom field value white.
// the meta_key 'color' with the meta_value 'white'
$rd_args = array(
'meta_query' => array(
array(
'key' => 'color',
'value' => 'white'
)
)
);
$rd_query = new WP_Query( $rd_args );
If you look at the post edit page (in admin area) in any post which matches the query, you will see the following in the “Custom Fields” section:
Refer this link More Knowledge