wp query – I need help using pre_get_comments to limit comments in the comments admin screen


The first (and only) parameter from the pre_get_comments hook is actually an instance of the WP_Comment_Query class and not WP_Query, so the $wp_query->set() won’t work because WP_Comment_Query does not have the set() method.

But you can directly access the $query_vars property in WP_Comment_Query to change the value of query args like the user_id. So for example with that arg, you would use $wp_query->query_vars['user_id'] = $user_ID;.

As for the FIXME part, try with the post_author arg: $wp_query->query_vars['post_author'] = $user_ID; which should work if you’re indeed trying to display only the comments made by the current user on the posts where that user is the author.

PS: I would rename $wp_query to $query or maybe $wp_comment_query.. I would also use $user_ID = get_current_user_id(); instead of relying upon the $user_ID global.

Fabian Amran 5 months 2021-07-03T04:40:18-05:00 0 Answers 0 views 0

Leave an answer