WordPress.org

Ready to get started?Download WordPress

Forums

MySQL Query to Find Topics with First Comment by a Particular Person (3 posts)

  1. WP User
    Member
    Posted 3 years ago #

    Hello everyone

    Its a MySQL related question.

    Is there any command to find out all wordpress topics which contain first comment by a particular person?

    I mean suppose I want to find out all topics which contain first comment by a person with name "xyz" or with email ID "xyz@abc.com".

    Can it be done?

    Any kind of help would be highly appreciated.

    Thanks.

  2. vtxyzzy
    Member
    Posted 3 years ago #

    The SQL query below should be close to what you want:

    $author = 'rupert';
    $sql = "
    SELECT p.*,c1.* FROM wp_posts p
    JOIN wp_comments c1 ON (c1.comment_post_ID = p.ID)
    WHERE c1.comment_author = '$author'
    AND c1.comment_date = (SELECT min(c2.comment_date)
       FROM wp_comments c2
       WHERE c2.comment_post_ID = c1.comment_post_ID)
    AND p.post_type = 'post'
    AND p.post_status = 'publish'";
  3. WP User
    Member
    Posted 3 years ago #

    ^^ Awesome. Thank you my friend. Worked like a charm. Just what I wanted. :D

Topic Closed

This topic has been closed to new replies.

About this Topic