Forums

[resolved] Check category-ID of a comment (2 posts)

  1. Sivar
    Member
    Posted 2 years ago #

    Hi there! :)

    I'm using Simple Recent Comments plugin, which accesses the wordpress database. Comments are being displayed as a list. So far, so good...

    Now I'd very much like to add a category-dependent class to the li-tags, so if one comment belongs to a post of category 10, I want a "<li class="cat10"> *link to comment* </li>" and so on for other categories.

    Problem is, that the comments table in the wordpress database doesn't have something like a "comment_cat_ID" field, just one for the post ID. What I need to find out is, to which category-IDs the different post-IDs belong. That category-ID should then be stored in a variable, so I can include it in the output of the plugin. This is what I have so far (using post2cat table)...

    global $wpdb;
    
    // [...]
    
    foreach ($comments as $comment) { // $comments is the result of an earlier db request for comments
    $sql = "SELECT category_id
    FROM $wpdb->post2cat
    WHERE post_id = $comment->comment_post_ID";
    
    $cat = $wpdb->get_results($sql);
    $cat = $cat->category_id;
    // *output*
    }

    $comments->comment_post_ID is definitely set... I tried outputting them for testing. I was hoping, the correct category-ID would now be adequately assinged to $cat, but it's not. $cat remains just empty.

    Does anyone have suggestions? Would be very much appreciated! Thx in advance! :)

  2. Sivar
    Member
    Posted 2 years ago #

    Never mind, some genius I know solved my problem ;).

Topic Closed

This topic has been closed to new replies.

About this Topic