Tag Info

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 ...


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

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 /** ...


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

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( ...


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 ...


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

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 ) ); To get the total number of all comments of all posts on the current page, you can use the comment_count property ...


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

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 ...


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

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

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

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 ...


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

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; } ...


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); ...


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

For comments: function count_comments_in_period( $date_from, $date_to ){ global $wpdb; $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_date >= %s AND comment_date < %s ", $date_from, $date_to)); return $count; } Just use dates in yyyy-mm-dd format. For posts: function ...


1

I don't have time to build both functions and I don't have time to test this one very much but I think this is at least close: function funky_comment_query_wpse_108830($year, $month, $hour) { if (!empty($year)) { $sql[] = "YEAR(comment_date) = {$year}"; } if (!empty($month)) { $sql[] = "MONTH(comment_date) = {$month}"; } if ...


1

In your functions.php add ( there are other rules relating to comment pages you can see them all with Rewrite Rules Inspector plugin, this one just covers the case you mention ) add_rewrite_rule ( '(.?.+?)/customname-([0-9]{1,})/?$', 'index.php?pagename=$matches[1]&cpage=$matches[2]', 'top' ); you'll also need to find in your theme ( possibly ...


1

offset parameter of get_comments() function accepts integer values for more information visit this codex page. so your get_comments function call should be as following. $numbers = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5); $random_key = array_rand($numbers, 1); $comments = get_comments(array('orderby' => 'comment_karma', 'number' ...


1

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.


1

As far as I remember awaiting moderation message should be only visible to author of the comment. If it is displaying otherwise it might be faulty caching implementation or other code interfering. The customization of it depends on where it is coming from - it can be WP core, core theme or third party theme using same string.


1

Sohag, you are seeking get_comments(). See the Codex. <?php $args= array( 'author_email' => '', 'ID' => '', 'karma' => '', 'number' => '', 'offset' => '', 'orderby' => '', 'order' => 'DESC', //ASC or DESC 'parent' => '', 'post_id' => 0, 'post_author' => '', 'post_name' => '', ...


1

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.


1

//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 ...



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