[英]Having Issues getting custom posts by Advanced Custom Fields (meta_key and meta_value)
I don't know why I am having this issues, I've done this sort of thing before, hopefully somebody can help shed some light on this situation. 我不知道为什么会有这个问题,我之前做过这样的事情,希望有人可以帮助您弄清这种情况。
$arch_state = get_field('service_area_archive_state');
$args01 = array(
'post_type' => 'service-area',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'meta_key' => 'service_area_state',
'meta_value' => $arch_state
);
$serv_areas = get_posts($args01);
then, I use a foreach loop to go through the query. 然后,我使用一个foreach循环进行查询。
foreach($serv_areas as $post) {
setup_postdata($post);
...
wp_reset_postdata();
}
for some reason, this query isn't returning anything. 由于某种原因,此查询未返回任何内容。 I am able to get the all the posts of that custom post type without an issue when I remove the meta_key and meta_value fields.
删除meta_key和meta_value字段时,我可以毫无问题地获取该自定义帖子类型的所有帖子。
But for some reason, as soon as I add the meta key and meta value, nothing... 但是由于某种原因,一旦我添加了元键和元值,就什么也没有...
Any ideas? 有任何想法吗?
Not sure if you need to put two quotations '' between $arch_state so its like this: 不知道是否需要在$ arch_state之间放置两个引号'',因此如下所示:
$args01 = array(
'post_type' => 'service-area',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'meta_key' => 'service_area_state',
'meta_value' => '.$arch_state.'
);
Try to set value there and see if its working 'meta_value' more you can see here: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/ 尝试在此处设置值,然后查看是否可以正常使用“ meta_value”: https ://www.advancedcustomfields.com/resources/query-posts-custom-fields/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.