Wordpress 更改主WP_Comment_查询(帖子底部的评论)?

Wordpress 更改主WP_Comment_查询(帖子底部的评论)?,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我的插件通过我自己的WP_Comment_查询在文章开头检索了一些评论。我保存这些ID,这样我就可以修改WP_Comment_查询请求,而不获取这些ID 当我使用pre_get_comments钩子隐藏这些已经获取的ID时,它们也会在每篇文章开头的第一次查询中隐藏。这是不切实际的 $this->loader->add_action( 'pre_get_comments', $plugin_public, 'hide_the_comments' ); public function

我的插件通过我自己的WP_Comment_查询在文章开头检索了一些评论。我保存这些ID,这样我就可以修改WP_Comment_查询请求,而不获取这些ID

当我使用pre_get_comments钩子隐藏这些已经获取的ID时,它们也会在每篇文章开头的第一次查询中隐藏。这是不切实际的

$this->loader->add_action( 'pre_get_comments', $plugin_public, 'hide_the_comments' );

public function hide_the_comments( $comment_query ) {

    $comment_query->query_vars['comment__not_in'] = $the_ids_to_hide;
}
我们如何才能只针对底部请求,就像post循环中有\u main\u query()一样?

  • 创建一个私有变量,例如
    private$count=0
  • 每次运行函数时,将其递增
  • 如果是第一次运行,请不要隐藏注释:)
如果需要在
Comments\u template()
核心函数中定位“main”
WP\u Query\u Comments()
,则
Comments\u template\u Query\u args
过滤器将从WordPress 4.5开始:

$comment_args = apply_filters( 'comments_template_query_args', $comment_args );
$comment_query = new WP_Comment_Query( $comment_args );

有关更多信息和一个简单示例,请参阅ticket。

可以工作,但我运行了数量不可预测的wp\u comment\u查询。我改变了我的方法,而不是使用pre_u钩子,我只是使用comment_u模板钩子,用自己的布局运行自己的查询。