douzuita7325 2018-09-15 11:35
浏览 54

WordPress后端显示具有特定注释数的帖子

I created a function which displays posts with specific number of comments.

function wpse45436_posts_filter( $query ) {

    global $post_type, $pagenow; 
    if ($pagenow == 'edit.php' && $post_type == 'post') {

        if (isset($_GET['reviews'])) {

            $reviews_number = sanitize_text_field($_GET['reviews']);
            $query->query_vars['comment_count']['value'] = $reviews_number;
            $query->query_vars['comment_count']['compare'] = '>=';
        }
    }
}
add_action('pre_get_posts','wpse45436_posts_filter');

The code above gets a review number of 100 for example and then shows posts which have more than 100 comments.

However, I want to show posts between 100 and 150 comments for example. So, Is there any way I can add AND in the above code to define show posts with comments number?

  • 写回答

1条回答 默认 最新

  • donglin7383 2018-09-15 11:44
    关注

    You may use something like this:

    $query->query_vars['comment_count']['value'] = [100,150];
    $query->query_vars['comment_count']['compare'] = 'BETWEEN';
    

    BETWEEN is standard MySQL operator.

    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了