I manage a small site that has a very active comment area. The site is on shared hosting. There is a daily post entry, then a robust comment area. It is not untypical to have more than 100 comments on a day's post. The result is that loading or refreshing the current day's page is very slow - up to or more than 30 seconds. Sometimes a page load will time out with a 500 error. Other times a comment …
Is there a similar replacement of the hook posts_where for comments (WP_Comment_Query)? I need to modify the where clause for a comments query like it is shown in this tutorial (“4. Sub custom field values”) for posts. The only hook I found is comments_pre_query, but the property $query->meta_query_clauses[ 'where' ] is protected.
I am trying to display the current user's ALL comments in a specific page and I'm using this code (uses a shortcode): https://blog.ashfame.com/2011/01/show-recent-comments-particular-user-wordpress/ And have modified it: <?php /* Plugin Name: Show Recent Comments by a particular user Plugin URI: http://blog.ashfame.com/?p=876 Description: Provides a shortcode which you can use to show recent comments by a particular user Author: Ashfame Author URI: http://blog.ashfame.com/ License: GPL Usage: */ add_shortcode ( 'show_recent_comments', 'show_recent_comments_handler' ); function show_recent_comments_handler( $atts, $content = null ) { extract( …
I am trying to make comments private. I mean comment must be visible for post author and comment author. I create custom comment section "better-comment.php". I have used pre_get_comments but I can not make work. Please help <?php // My custom comments output html function better_comments( $comment, $args, $depth ) { // Get correct tag used for the comments if ( 'div' === $args['style'] ) { $tag = 'div'; $add_below = 'comment'; } else { $tag = 'li'; $add_below = …
I need some customization of WORDPRESS comment area, so I've used this code in my child theme : <div id="comments" class="x-comments-area"> <?php if ( have_comments() ) : ?> <?php //The author of current post $author_ID = get_the_author_meta("ID"); //The current post ID $p_ID = get_the_ID(); ?> <h2 class="h-comments-title"><span><?php _e( 'Comments' , '__x__' ); ?> <small> <?php //Number of guest comments echo ztjalali_persian_num(number_format_i18n(count(get_comments(array('post_id' => $p_ID,'author__not_in' => array($author_ID)))))); ?></small></span></h2> <ol class="x-comments-list"> <?php wp_list_comments( array( 'callback' => 'x_icon_comment', 'style' => 'ol' ) ); ?> …
I am working on a code through which I can send emails to the user when his/her comments get approved. then I get to know about comment_post. but it is not working. comment_post is working for the condition in which user adds a new comment it sends the mail but not when the comment get approved.. #Means ($comment_approved === 1) is not working. here is my current and same code as I found on the internet - function show_message_function( $comment_ID, …
i want to pin all comments from post with commentmeta = 'spolie' on the top of my comment list in post. Quite similar to Instagram pin comment or wpdiscuz pin comment; Can someone help me. tnx :)
The query string comment__in takes an array of comment IDs to include. I have an array of comment IDs that I would like to assign to comment__in, such as $args['comment__in'] = $comment_IDs;. Some comment IDs in $comment_IDs do not exists in the database and some do. Regardless, when a comment ID exists in the database, it gets returned by get_comments($args). However when none of the comments IDs in $comment_IDs exist in the database, get_comments($args) returns a large number of comments …
My comment form has validation so that when a user tries to post a blank comment, it currently shows the "This field is required" message under the comment box. How do I change the message content to "Please enter your comment."? I'm guessing that the following line of code might do the trick but I don't know how to nest HTML code in my functions.php file. document.getElementById("comment-error").innerHTML = "Please enter your comment."; Any help would be most appreciated.
I've written code to display a table with columns containing: post date post title number of comments of users with certain groups (actually certain meta data). The following code only works correctly until the fourth loop, which is the fourth row in the table. function generate_post_report() { if(is_page( 3815 )){ $current_user = wp_get_current_user(); $args = array( 'hide_empty' =>0, 'orderby' => 'post_date', 'exclude' =>array(1, 464), // desire id ); ob_start(); $categories = get_categories($args); if ($categories){ foreach ( $categories as $category ){ …
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 ); if ( $comments ) { $output.= "<ul>\n"; foreach ( $comments as $c ) { $output.= '<li>'; $output.= '<a href="'.get_comment_link( $c->comment_ID ).'">'; $output.= get_the_title($c->comment_post_ID); $output.= …
How do I only get the first level of comments in get_comments() or WP_Comment_Query? I want to query the comments which have 'comment_parent' => 0, and exclude all the child comments. $args = array( 'number' => 10, 'order' => 'DESC', 'status' => 'approve', 'meta_key' => 'comment_parent', 'meta_value' => 0 ); $comments = get_comments( $args );
Author's and visitors' names use the same color in comments.The point here is that the color of the author's name is different in the comments. For example, in visitor comments, name is red. But, the name of the site author should be gray. (Only in comments) I know an ID needs to be added for the author's comments. However, I could not add this ID. Therefore, the style I gave in style.css does not work either. I just tried this …
I'm creating a custom user status page for my members. I need to show the comments count of the wp_get_current_user(). I looked at WP_Comment_Query but unable to understand anything. My conditions are: comment_type : review_comment comment_approved : 1
How would I count (and display) the number of times a comment meta field's value is a post's entire comments? e.g. meta key is "fish" and key value "shark" appears in 5 comments of a 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 all cars, even each car has different average consumption. For example: Car 1 mpg (28;25;39 - avg 30.6) Car 2 mpg (44;50 avg 47) And …
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 top-level comments, and all the replies those top-level comments might have. How do I achieve this? Current Code $args = array( 'post_id' => $post_id, 'type' …
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', 'hierarchical' => true ); if ( $orderby == 'top-comments' ) { $args['meta_key'] = 'comment_rating'; $args['orderby'] = 'meta_value_num'; $args['order'] = 'ASC'; } // $comments_query = new …
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 object. However, I need to query comments and order them by passing advanced query args. So I use WP_Comment_Query to create a new object that …