WordPress函数:WP_Query 按评论数量查询文章

追格官方小助手/ 2022年07月09日/ WordPress/ 浏览 1333

在WordPress中,强大的WP_Query还支持按评论数量查询文章。


需要使用 comment_count 参数,如果传入int,比如100,则查询评论数为100的文章;如果传入 Array,字段value为int,compare 则支持 '=', '!=', '>', '>=', '<', '<=' 等。


代码示例:


// 传入 int
$args = array(
    'post_type' => 'post',
    'comment_count' => 20,
);
$query = new WP_Query( $args );

// 传入 Array
$args = array(
    'post_type' => 'post',
    'comment_count' => array(
        'value' => 25,
        'compare' => '>=',
    )
);
$query = new WP_Query( $args );


WP_Query 的基础用法可以参考文章:WP_Query 的基础用法简介

发表评论

暂无评论,抢个沙发...

客服 工单