Hot answers tagged

7

To record the moderator that approves the comment: function wpse_comment_moderator_log( $comment ) { global $current_user; get_currentuserinfo(); update_comment_meta( $comment->comment_ID, 'approved_by', $current_user->user_login ); } add_action( 'comment_unapproved_to_approved', 'wpse_comment_moderator_log' ); To display it after the ...


5

The 'post_id' is converted to a positive integer in WP_Comment_Query, so you cannot successful pass anything else to get_comments(). You have to filter 'comments_clauses'. Here you can change the WHERE clause to use comment_post_ID IN ( $ids ) instead of comment_post_ID = $id. I would use a static class as a wrapper for get_comments(). Sample code /** ...


5

Unfortunately, get_comments() doesn't quite work that way. If you specify a post ID, the function will only return comments for that post. The post ID parameter does not accept multiple IDs. However, you could write a function to recursively fetch comments from an array of posts and use that instead: get_comments_from_range( $post_ids ) { foreach( $...


4

Easy: function show_portfolio_comments( $post_ID ) { // NOT approved $comments_unapproved = get_comments( array( 'status' => 'hold', 'post_id' => $post_ID ) ); foreach ( $comments_unapproved as $comments) { if ( current_user_can( 'edit_published_posts' ) // maybe you'll have to switch to some other cap { ?> ...


4

To print just the total number of comments for a given post ID, use the count argument: echo get_comments( array ( // post ID 'post_id' => 149, // return just the total number 'count' => TRUE ) ); or just use // Argument: Post ID echo get_comment_count( 149 ); To get the total number of all comments of ...


3

You cannot do that with a parameter for get_comments(), but filtering 'comments_clauses' should do it. Sample code, not tested: add_filter( 'comments_clauses', 'wpse_78490_child_comments_only' ); function wpse_78490_child_comments_only( $clauses ) { $clauses['where'] .= ' AND comment_parent != 0'; return $clauses; }


3

I don't know why somebody downvoted this question. This is a GREAT question. Yeah, that's totally possible. What you would want to do is use comment_meta to store the titles. You could add the new field into the form using the 'comment_form_top' action. It runs before name, email, and url, and still runs if the user is logged in, so you'd get the field for ...


3

You're really close! Add #comment-<?php comment_id(); ?>to the href to append the anchor link <a href="<?php echo get_permalink($comment->comment_post_ID);?>#comment-<?php comment_ID() ?>"> <?php echo $post->post_title; ?> </a>


3

Give it a try works perfect for me what it is doing query get the all the posts with a left jon with comments table so when a post has comment then it also has the comment_date if no comments posted on the post then in result set it will be null so i have merged the comment_date with post_date so which post has the greater date (for comment_date or ...


3

Try this: <?php $popular = new WP_Query('orderby=comment_count&posts_per_page=5'); ?> <?php while ($popular->have_posts()) : $popular->the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> has <?php comments_number( 'no responses', 'one response', '% responses' ); ?>.&...


3

There is no wp_comment_count in a WP_Query object, either in the "top" level as in your code-- $popular->wp_comment_count-- or in the individual post objects which is what you actually want to be checking. There is a comment_count in the post objects though, and that is what you want-- $post->comment_count. Your code should look like this (cleaned ...


2

I cannot find that function in source and also not sure about your code nesting there. There is paginate_comments_links() function. Usage is around this: if ( get_option( 'page_comments' ) ) paginate_comments_links();


2

Not possible. You have to filter comments_clauses: add_filter( 'comments_clauses', 'wpse_77415_comment_clauses_filter' ); function wpse_77415_comment_clauses_filter( $clauses ) { $clauses['where'] .= " ( comment_approved = 'hold' OR comment_approved = 'trash' )"; // maybe remove the original 'comment_approved' statement … return $clauses; } ...


2

As of the Wordpress codex there is no such option. But you could just combine two or more comment arrays using plain PHP: array_merge( get_comments( array( 'status' => 'hold' ) ), get_comments( array( 'status' => 'trash' ) ) ); http://codex.wordpress.org/Function_Reference/get_comments http://php.net/array_merge


2

Aha, I think my syntax was wrong. I changed: action: 'do_ajax', data: { 'post_id' : '72' //using a post id that I *know* has comments, for testing! }, to: data: { 'action' : 'do_ajax', 'post_id' : '72' }, and I'm getting the correct response from the console.log which shows: [{"comment_ID":"1","comment_post_ID":"1","comment_author":"Mr ...


2

Most likely, the main thing that you missed is that you must have "Break comments into pages" checked in the Settings Discussion Subpanel. The pagination functions require this to be set, as do the URL rewrites. Here's a working, complete page template to do what you're asking: <?php /* Template Name: All Comments See http://wordpress.stackexchange.com/...


2

In the wordpress codex function reference for comments, it looks like the parameter for the parent is not comment_parent but just parent. Which is weird and inconsistent because the return values are prefixed with comment_.


2

From the look at code WP_Comment_Query class, used internally by get_comments() allows orderby argument to be set to 'meta_key' string to sort by key in argument of same meta_key name.


2

You can try to modify the query using the comments_clauses filter: $args = array( 'user_id' => 0 ); add_filter( 'comments_clauses', 'custom_comments_clauses'); $comments = get_comments( $args ); remove_filter( 'comments_clauses', 'custom_comments_clauses'); function custom_comments_clauses( $clauses ){ $clauses['where'] = str_replace( 'user_id = 0', ...


2

I realized that comment-reply.js is not loaded and it fixed the issue. Could someone explain? I have no idea what happened. So the fix was adding wp_enqueue_script( 'comment-reply' ); to my plugin code.


2

//check if user has previously commented the post. global $current_user, $post; if ( !is_user_logged_in() ) { comment_form(); } else { $usercomment = get_comments(array('user_id' => $current_user->ID, 'post_id'=>$post->ID) ); if($usercomment) { echo '<p>Vous avez déjà signé cette ...


2

get_comments do not get a post ID as parameter but rather an array in which you can set all kinds of query criteira including post ID. See the codex http://codex.wordpress.org/Function_Reference/get_comments. You can even use the author_email parameter to make get_comments do most of the work for you.


2

You're re-inventing the wheel here ;-) The Problem You're bypassing WordPress with this approach, so that's explains the error message. Accessing any custom file, within your theme directory, will not load WordPress core automatically. Already available This is already supported by the WordPress core. You should check out comments_popup_link() and ...


1

I don't know of a way to directly pull this query with Core functions, but the SQL is simple. $sql = "SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE comment_author = 'admin' AND DATE(comment_date) = FROM_UNIXTIME('".time()."')"; $a = $wpdb->get_var($sql); You can alternately use something like AND DATE(comment_date) ...


1

Yes it's definitely possible. Refer to http://codex.wordpress.org/Function_Reference/get_comment, you'll need to get the current server time in UNIX format and then convert comment_date_gmt from each returned be using a foreach loop function current_user_comments_today() { global $comment; global $current_user; get_currentuserinfo(); $all_user_comments ...


1

In the wp_comments table, if comment_parent equals 0, it's a first-level comment. function get_num_toplevel_comments() { global $wpdb; return $wpdb->get_var(" SELECT COUNT(*) FROM $wpdb->comments WHERE comment_parent = 0 "); }


1

paginate_comment_links() actually does some magic setup for comments and then calls the standard wordpress paginate_links(). I believe that part of that magic utilizes the result of wp_list_comments(). So even though your code is works great - you cannot use the built-in paginate comments functionallity because you are not using wp_list_comments(). And ...


1

use the "parent" parameter as 0. $args = array( 'parent'=>0 'post_type' => 'custom-post-type', 'number' => '1', 'orderby' => 'date', 'order' => 'DESC' ); $comments = get_comments($args); foreach($comments as $comment) : echo($comment->comment_author . '<br />' . $comment->comment_content); endforeach;...


1

You have a couple potential issues: Your version of WordPress and/or your current Theme does not support threaded comments. What version of WordPress are you using? What Theme are you using? Something is interfering with comment display What Plugins are you using, that might be interacting with comments? These would include anti-spam Plugins, security ...


1

$args = array('post_id'=>get_the_ID(), 'status'=> 'approve'); $all_comm = get_comments($args); $per_page = get_option("comments_per_page"); if(!$per_page) $per_page = 4; $cpage = get_query_var("cpage"); if(!$cpage) $cpage = 1; if(round(count($all_comm)/$per_page) == 0) $total = 1; else $total = round(count($...



Only top voted, non community-wiki answers of a minimum length are eligible