Articles of wp comment query

List user comments in author page

I’m trying to display a list of the author comments in the authors page but it only shows No comments made. How can I list user comments in the authors page? <?php $args = array( ‘user_id’ => $user->ID, ‘number’ => 10, // how many comments to retrieve ‘status’ => ‘approve’ ); $comments = get_comments( $args […]

How to query comments only for the current post?

I am using ACF and my comments have custom fields. I also have custom post type called cars. What I’m trying to do is to make users comment their average consumption, and then I calculate average consumption for single car. I did that, and it works well except one part. Average consumption is same for […]

WP_Comment_Query with 5 top level comments per page?

I’m trying to replicate the option in WordPress’s settings page that says: [x] Break comments into pages with ((5)) top level comments per page and the ((first)) page displayed by default Right now I have the following comment query, but it only displays 5 comments, also counting the replies. The behavior I want is 5 […]

WP_Comment_Query() displays “password protected” comments?

It appears that looping through wp_comment_query() with the argument post_status set to publish also lists comments that are posted on password protected posts. Is this the correct behavior or is this a bug? How can I avoid looping through comments submitted to password protected posts? I checked through the database wp_comments table and there doesn’t […]

Exclude comments from a WP_Query object?

I have noticed that the default WP_Query object also contains all of a post’s comments. global $wp_query; print_r($wp_query->comments); // Prints an object containing all of a post’s comments From my understanding, WordPress somehow combines a post query and a comments query into one WP_Query object, and then displays a post’s comments by reading the $wp_query->comments […]

Custom WP_Comment_Query with pagination and orderby?

I’m trying to setup a custom WP_Comment_Query which is ordered by a meta key. (It might be worth mentioning that these comments are being retrieved with AJAX.) It all works fine, until I add in pagination into the query args. $orderby = ‘top-comments’; $args = array( ‘post_id’ => $post_id, ‘type’ => ‘comment’, ‘status’ => ‘approve’, […]