简体   繁体   English

通过高级自定义字段(meta_key和meta_value)获取自定义帖子时遇到问题

[英]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.

相关问题 通过在Wordpress中由meta_key和meta_value标识的自定义查询字符串来检索发布 - Retrieve Post by Custom Query String identified by meta_key and meta_value in Wordpress WP->查询从meta_value和meta_key获取自定义帖子ID - WP->Query get Custom Post ID from meta_value & meta_key 如何确定高级自定义字段meta_value? - How is the Advanced Custom Fields meta_value determined? 使用带有Ajax的select元素按WordPress中的一个meta_key和两个meta_value过滤帖子 - Filter posts by one meta_key and two meta_value in WordPress using a select element with Ajax 高级自定义字段按元键值排序 - Advanced Custom Fields Order By Meta Key value 如果 meta_key = Delivery Date 和 meta_value = this day,则在 WooCommerce 每天 23:00 将订单状态从自定义状态更新为已完成 - Update order status from custom statuses to completed in WooCommerce everyday at 23.00 if meta_key = Delivery Date and meta_value = this day 构造MySQL查询(meta_key / meta_value表) - Construct MySQL query ( meta_key/meta_value table) WPDB查询-根据_meta_key返回meta_value - WPDB Query - Return meta_value based on _meta_key 如何通过meta_value和meta_key检索meta_values的结果? - How to retrieve results of meta_values by meta_value and meta_key? WordPress-列出具有特定meta_key值的自定义类型 - WordPress - List Custom Type With Specific meta_key value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM