列出自定义字段为特定值时的帖子

问题描述 投票:0回答:1

我试图根据每篇文章中选择的“样式和艺术”选择框来输出特定文章类型的标题列表。

下面的代码似乎除了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个回答
1
投票

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

    array(
        'key' => 'you_may_also_like',
        'value' => 'true'
    )
© www.soinside.com 2019 - 2024. All rights reserved.