[resolved] template - get comment author information in the Loop (3 posts)

  1. zoekatz
    Posted 8 years ago #

    I am trying to go through the comments loop inside of the post Loop and return a list of all the authors who have commented.

    I put the following into the Loop (which doesn't work - my Loop is working and returning other information) -

    <?php foreach ($comments as $comment) : ?>
    <?php global $comment; ?>www<?php echo $comment_author; ?>
    <?php endforeach; ?>

    What I'm doing is writing xml from the php to go into a flash interface for my blog. I need to know all the names of the people who have commented (everyone is logged in) or more specifically if the user that is logged in currently has commented on the post. This information needs to be in a string on this page and inserted into the XML that I'm creating with the Loop that goes through all of the posts.

    Thanks for any advice on this.

  2. Kafkaesqui

    Posted 8 years ago #

    Problem here is the $comments object does not exist until the comments template is loaded. You'll have to query the database to get at them:

    $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date");
    foreach( $comments as $comment ) :
  3. zoekatz
    Posted 8 years ago #


Topic Closed

This topic has been closed to new replies.

About this Topic