【问题标题】:I have ACF installed and activated, but can't use them to select certain WP pages based on custom fields我已安装并激活 ACF,但无法使用它们根据自定义字段选择某些 WP 页面
【发布时间】:2019-11-18 02:45:26
【问题描述】:

我正在尝试查询 WP 页面并根据 ACF 自定义字段数据显示其标题。 我的ACF字段是promotion_url,需要的值为3。

这是我使用的代码:

    <?php
$args = array(
    'post_type' => 'page',
    'post_status' => 'publish',
    'meta_query' => array(
        array(
            'key' => 'promotion_url',
            'value' => '3',
        )
    )
); $my_query = new WP_Query($args)?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
                <li>
                <?php the_title(); ?>
                </li>
            <?php endwhile; ?>

谁能帮帮我,我做错了什么?

如果我删除这部分,我可以毫无问题地显示所有页面的标题。

'meta_query' => array(
    array(
        'key' => 'promotion_url',
        'value' => '3',
    )
)

【问题讨论】:

    标签: php wordpress field advanced-custom-fields


    【解决方案1】:

    因为您没有在数组中设置“比较”的值:请尝试:

    'meta_query' => array(
        array(
            'key' => 'promotion_url',
            'value' => '3',
            'compare'   => '=',
        )
    )
    

    您可以在here查看文档以使用ACF查询

    【讨论】:

      猜你喜欢
      • 2016-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-17
      相关资源
      最近更新 更多