更改主要 WP_Comment_Query(帖子底部的评论)? [英] Alter the Main WP_Comment_Query (comments at the bottom of posts)?

查看:35
本文介绍了更改主要 WP_Comment_Query(帖子底部的评论)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的插件通过我自己的 WP_Comment_Query 在帖子开头检索了一些评论.我保存了这些 ID,这样我就可以更改 WP_Comment_Query 请求,而不是获取这些 ID.

My plugin retrieves a few comments at the beginning of the post through my own WP_Comment_Query. I save these IDs so I can then alter the WP_Comment_Query request and not fetch these IDs.

当我使用 pre_get_comments 钩子隐藏这些已获取的 ID 时,它们也会在我每篇文章开头的第一个查询中隐藏.它违背了这一点.

When I use the pre_get_comments hook to hide these already-fetched IDs, they are also hidden from my first query at the beginning of each post. It defies the point.

$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 循环有 is_main_query() 一样?

How can we target the bottom request only, just like there is is_main_query() for the post loop?

推荐答案

如果您需要针对 comments_template() 核心函数中的主要"WP_Query_Comments(),那么 comments_template_query_args 过滤器是 可用 自 WordPress 4.5 起:

If you need to target the "main" WP_Query_Comments() within the comments_template() core function, then the comments_template_query_args filter is available since WordPress 4.5:

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

请参阅票证 #34442 了解更多信息和简单示例 此处.

See ticket #34442 for more info and a simple example here.

这篇关于更改主要 WP_Comment_Query(帖子底部的评论)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆