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

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

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

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


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


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

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


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

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

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

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

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

This should do the trick, I guess: $args = array( 'number' => 10, 'order' => 'DESC', 'status' => 'approve', 'parent' => 0 ); $comments = get_comments( $args ); You can find full list of arguments in Codex.


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

Use get_comments( $args ) to get all the comments for a post. $args= array( 'author_email' => '', 'ID' => '', 'karma' => '', 'number' => '', 'offset' => '', 'orderby' => '', 'order' => 'DESC', 'parent' => '', 'post_id' => 0, 'post_author' => '', 'post_name' => '', 'post_parent' ...


1

What you need to do to achieve this is to provide the second parameter of wp_list_comments(), which would be $comments and is described like this: (array) (optional) Array obtained by get_comments query. Default: The default return of get_comments. Which actually makes it clear what you need to do, which would be utilizing get_comments(). Below ...


1

Constructing the SQL query: You can try the following: /** * Fetch comments' IDs for the most recently commented posts * (only one comment per post) * * @param integer $count * @return array */ function get_cids_wpse ( $count = 5 ) { global $wpdb; $sql = "SELECT MAX( comment_ID ) as cid FROM {$wpdb->comments} ...


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



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