$posts = new WP_Query( [
'post_type' => 'mock_test',
'meta_query' => array(
'key' => 'selectedchapter',
'value' => 15
),
] );
echo "<pre>";
print_r($posts);
echo "</pre>";
I need to get posts which have selected chapter 2 in custom meta box. This WP_Query not working for me, I’m getting all the posts.
see attached screenshot (https://prnt.sc/vuzw6lhW44mR) of metabox html structure.
2
Answers
This is a simple way to get post where the custom field key is ‘color’ and the custom field value is ‘blue’:
Try these code