How to make comments private for commentor and post author

You can use the pre_get_comments filter to modify the parameters of the comment query before it fetches the comments. Specifically the author_in parameter. I tried to write an example, though I haven’t tested it, but it would be similar to this: add_action( ‘pre_get_comments’, ‘author_and_self_comment_filter’ ); function author_and_self_filter( \WP_Comment_Query $query ) : void { // We … Read more

List user comments in author page

Try with WP_Comment_Query and make sure you have the right Author ID from the Author Template. // WP_Comment_Query arguments $args = array ( ‘user_id’ => $user->ID, ‘post_status’ => ‘approve’, ‘number’ => ’10’, ); // The Comment Query $comments = new WP_Comment_Query; $comments = $comments->query( $args ); // The Comment Loop if ( $comments ) { … Read more

How would I count the number of times a comment meta field’s value is in a post’s entire comments?

You should be able to do a meta_query in a WP_Comment_Query(): $args = array( ‘post_id’ => ‘post-id-here’, ‘meta_query’ => array( array( ‘key’ => ‘fish’, ‘value’ => ‘shark’, ‘compare’ => ‘LIKE’ ) ) ); // Query the comments $comment_query = new WP_Comment_Query( $args ); // Count the number of comments $count = count ( $comment_query ); … Read more

WP_Comment_Query with 5 top level comments per page?

Updated The hierarchical parameter controls whether to include comment descendants in the comments results. From the inline docs we have that it accepts the following values: ‘threaded’ returns a tree, with each comment’s children stored in a children property on the WP_Comment object. ‘flat’ returns a flat array of found comments plus their children. false … Read more

How to put this result inside that result?

Run the loop in advance and populate an array, which in turn you include in the $result afterward. <?php // Create an empty array $comlistall = array(); foreach ( $comments as $comment ){ $comlistall[] = $comment; // <= Populate the array with the comments in the loop }; $rtitlez = get_the_title(); $rimgz = get_the_post_thumbnail_url(get_the_ID(), ‘full’); … Read more