Support » Plugins and Hacks » Parse the comment number for a plugin

  • Hi all,
    I’m quite a newby when it comes to creating plugins and the Plugin APIs and I’m having some trouble.

    I am trying to figure out a way to get the comment number of a certain post (thus within the loop) so I can use this number in a plugin. The hooks and filters do not seem to do the job, so all I’ve got now is that it keeps echoing the comment number instead of parsing it as a string for use within php.

    Anyone an idea?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The hooks and filters do not seem to do the job

    What hooks and filters? What are you presently doing to try and collect the comment count?

    Just query the database…

    $numberofcomments = $wpdb->query("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '45' AND comment_approved = '1'");

    Thanks, I was already working on that but it didn’t work at all.
    I rewrote the script you gave me a bit to:

    global $wpdb, $post_id;
    $get_comments_number = “SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = ‘1’”;
    if (!$all_posts) $get_comments_number .= ” AND comment_post_ID=$post_id”;
    $comments = $wpdb->get_var($get_comments_number);

    Thanks for the help! Now, I’ve written my 3rd plugin (very simplistic ones) and maybe I’ll get the hang of it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Parse the comment number for a plugin’ is closed to new replies.