【问题标题】:List posts when custom field is specific value当自定义字段为特定值时列出帖子
【发布时间】:2014-11-29 11:40:02
【问题描述】:

我正在尝试根据在这些帖子中选择“风格和艺术”选择框的时间来输出特定帖子类型的标题列表。

下面的代码似乎除了开始和结束 ul 标记之外没有输出任何东西。

但是,如果我删除 meta_query 数组,那么它会列出所有帖子类型。

<ul>
    <?php
    $args = array(
        'post_type' => 'profiles',
        'meta_query' => array(
            array(
                'key' => 'you_may_also_like',
                'value' => 'Style & Art'
            )
        )
    );

    query_posts($args);

    while ( have_posts() ) : the_post();
        echo '<li>';
            the_title();
        echo '</li>';
    endwhile;

    wp_reset_query(); ?>
</ul>

我需要能够根据特定标准过滤它们,但目前没有任何运气。

【问题讨论】:

    标签: wordpress custom-post-type advanced-custom-fields


    【解决方案1】:

    我认为这里的问题是价值' => '风格与艺术'。我怀疑“风格和艺术”是价值,而只是复选框的标签。请尝试以下操作:

        array(
            'key' => 'you_may_also_like',
            'value' => 'true'
        )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-24
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多