WP_Query cat an 标签不工作的帖子

WP_Query posts by cat an tags not working

提问人:btgen 提问时间:5/30/2022 最后编辑:btgen 更新时间:5/30/2022 访问量:584

问:

我正在尝试通过猫标签获取一些帖子。这是我到目前为止得到的,但没有用。

任何帮助,那就太好了......

$pots = new WP_Query(array('cat' => array (591),
'tax_query' => array(
        array(
            'taxonomy' => 'post_tag',
            'field'    => 'name',
            'terms'    => array('my tag', 'my tag2'),
        ),
    ),
     'posts_type' => 'post',
     'showposts' => 32,
     'paged' => $paged,
     'order' => 'desc',
     'post__not_in' => get_option( 'sticky_posts' ),
     ));
wordpress 类别

评论


答:

0赞 Morteza Barati 5/30/2022 #1

我认为一切都很好,只是关于标签,我认为我应该使用 slug 而不是像我的代码一样的名称

$pots = new WP_Query(
    array(
        'cat' => array(591),
        'tax_query' => array(
            array(
                'taxonomy' => 'post_tag',
                'field' => 'slug',
                'terms' => array('my_tag', 'my_tag2'),
                'operator' => 'AND',
            ),
        ),
        'posts_type' => 'post',
        'showposts' => 32,
        'paged' => $paged,
        'order' => 'desc',
        'post__not_in' => get_option('sticky_posts'),
    )
);