Hot answers tagged get-comments
6
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
{
?>
...
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
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
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
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
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>
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
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
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;
}
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
You can try this query that counts user comments by using the user_id field in the comments table as a filter:
function count_user_comments_today( $uid ){
global $wpdb;
$today = date('Y-m-d');
$tomorrow = date('Y-m-d', time() + 86400);
$count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->comments} WHERE user_id = %d ...
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
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
1
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 ...
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);
...
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 = ...
1
Unfortunately it's unsupported by the applicable WordPress functions for querying comments, which is primarily due to(i feel) not enough people(or anyone) yet asking for it.
I want to highlight a couple of core files here to help understand the issue.
First up comments-template.php, the comment_template function, it's this function that queries for ...
1
$output .= "<li>".(($result->comment_author_url) ? "<a href='".$result->comment_author_url."'>" : "").$result->comment_author.(($result->comment_author_url) ? "</a>" : "")." (".$result->comments_count.")</li>";
edit:
to show the avatar before the name:
$output .= ...
1
You'll need to loop through your posts, use get_comments_number() to get the number of comments for each post, and then accumulate the total number of comments in a separate variable. e.g.:
<?php
$features_comment_count = 0;
if ( have_posts() ) : while ( have_posts() ) : the_post();
$features_comment_count += get_comments_number();
endwhile; endif;
...
1
Instead of $comment->post_ID use $comment->comment_post_ID. Your code will look like following:
<?php $comments = get_comments('status=approve&number=5'); ?>
<ul id="recent_comments">
<?php foreach ($comments as $comment) { ?>
<li><p><strong><?php
$title = ...
1
I don't use widgets for this as you can easily create one and use get_comments( $args ); for the most cases for example:
10 last comments by page is :
$args = array(
'post_id' => $post_id,
'number' => 10,
'status' => 'approve');
$comments = get_comments($args);
foreach($comments as $comment) :
...
1
add
to your loop and replace it with the the_permalink() function something like this:
<?php
// Include Wordpress
define('WP_USE_THEMES', false);
require('./blog/wp-load.php');
?>
<div>
<p style="font-size:18px;color:white;font-wieght:700;">Recently Asked Questions</p>
<?php query_posts('showposts=3'); ?>
<?php while ...
1
See.
http://codex.wordpress.org/Function_Reference/get_comments
Set the orderby parameter to your desired value, possible values are.
comment_agent
comment_approved
comment_author
comment_author_email
comment_author_IP
comment_author_url
comment_content
comment_date
comment_date_gmt
comment_ID
comment_karma
comment_parent
comment_post_ID
comment_type
...
1
This is correct..documentation is not updated on wordpress codex site.
I found the solution on following site.
http://wordpressapi.com/2012/01/25/show-the-comments-from-custom-post-type-in-wordpress/
1
What you try to achieve is a missing feature with the get_comments() function in WordPress. So it is basically not possible to get comments by post-type with the get_comments() function so far.
The related ticket is: Ticket #12904 - get_comments(): Enable post_status, post_type
You will need another function that is returning the data you are looking for. ...
Only top voted, non community-wiki answers of a minimum length are eligible