使用自定义META提交的自定义邮政类型帖子值WordPress
$posts = new WP_Query( [
'post_type' => 'mock_test',
'meta_query' => array(
'key' => 'selectedchapter',
'value' => 15
),
] );
echo "<pre>";
print_r($posts);
echo "</pre>";
我需要获取在自定义元框中选择第2章的帖子。这个WP_QUERY对我不起作用,我会收到所有帖子。 请参阅随附的屏幕截图( https://prnt.sc/vuzw6lhw44mr )。
$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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一种获取帖子的简单方法,即自定义字段键为“颜色”,自定义字段值为“蓝色”:
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