Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Could you please help me with some code to get all recent comments for posts that are tagged with for example "XYZ"?

Thanks in advance, you guys are great!

share|improve this question
    
This is quite unresearched on your side, but I'll post an answer anyway. –  fischi Jan 17 '13 at 10:38
add comment

2 Answers 2

As Konstantin Kovshenin pointed out in this article, you can get the comments for a specific Category like that:

<?php
$show_comments = 10;
$i = 0;
$comments = get_comments("number=50&status=approve");
foreach ($comments as $comment)
{
    $comm_post_id = $comment->comment_post_ID;
    if (!has_term( 'XYZ', $comm_post_id );)
        continue;
    $i++;

    // Output the comment, author and whatever you need
    // I'll just output the comment excerpt to keep my code simple
    ?><li><?php comment_excerpt(); ?></li><?php

    if ($i >= $real_comments) break;
}
?>
share|improve this answer
add comment

The given code doesn't work, I edited a bit, especially this line: if (has_term( "blogs", $comm_post_id ))

And it displays all comments, not just from 1 tag.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.