I need a solution that will allow users rate page content within a comment.

After that problem comes when I need show that comments(with rating stars) in different spot on my site where I display all of them in a carousel.

for now I have carousel with all needed information(comment author name or piece of comment content) and I'm missing only this rating system implementation:

    $args_count = array(
        'count' => true
    $comments_query_count = new WP_Comment_Query;
    $comments_count = $comments_query_count->query( $args_count );

    $args = array(
    $comments_query = new WP_Comment_Query;
    $comments = $comments_query->query( $args );

    if ( $comments ) {
        for ($i=0;$i<$comments_count; $i++) { ?>
                <div class="a24-carousel-item">
                    <div class="row">
                        <?php echo get_avatar($comments[$i]->comment_author_email);?>
                        <div class="HERE I NEED stars from specific comment"></div>
                        <p class="author"><?php echo $comments[$i]->comment_author ?></p>
                        <p class="date">Added: <?php echo $comments[$i]->comment_date ?></p>
                        <p class="associated-post"><?php echo get_the_title($comments[$i]->comment_post_ID) ?></p>
                        <p class="content">
                        <?php echo $comments[$i]->comment_content; ?>

Does anyone know a way how to help me displaying comment ratings in my carousel?

  • To answer the question we would need to know how the plugin works, that makes your question be off-topic; so, you need to ask to the plugin developer if it already has a method to display the ratings or how the ratings are stored in database (I guess it uses comment meta fields); then you will be closer to know how to get them and show them wherever you need. – cybmeta Jan 9 '17 at 11:54
  • i changed question not to focus on plugin but on solution – dmnmlk Jan 9 '17 at 12:16
  • Please add the relevant code and explain how the ratings info is stored in the database, that might help other users to suggest a solution. – birgire Jan 9 '17 at 12:22
  • After the update, the answer still needs to know the internals of the third party plugin; your question is still off-topic. – cybmeta Jan 9 '17 at 12:41
  • okay, now there is no link to third party plugin. I am looking for solution for my problem – dmnmlk Jan 9 '17 at 12:50

If the comment rating is stored in the comment meta, then you can use:

$rating = get_comment_meta( get_comment_ID(), 'some-meta-key', true );

where you need to adjust the some-meta-key accordingly.

If the comment rating is automatically injected into the comment's text via the comment_text filter, then you need to use the comment_text() function to display it.

Here's an example:

if ( $comments ) {
    foreach( $comments as $comment ) {
        // ...
        comment_text( $comment );

Note that here you don't need to run WP_Comment_Query twice, as you do in your snippet, just to get the number of comments.

There's also a core function for displaying star ratings: wp_star_rating()

  • Thanks for answer, but how i can adjust that meta-key? i have to add it first with add_comment_meta somehow? how i can add that, using hook or something? im aware of using foreach but later on carousel i need calc if number of comments are even to display it properly. – dmnmlk Jan 10 '17 at 10:47
  • Note that count( $comments ) gives you the comments count. You can e.g. check the wp_commentmeta table, ask the plugin author or check the plugin code to see if it's using add_comment_meta() @dmnmlk – birgire Jan 10 '17 at 10:55
  • aand it works! i found it in plugin code: add_comment_meta($commentID, 'crfp-rating', $_POST['crfp-rating'], true); now i took it by get_comment_meta and now i have values from 1 to 5 in my carousel. Now i just need display it properly, thanks so much for help and Your time :) – dmnmlk Jan 10 '17 at 11:00
  • glad to hear it worked for you @dmnmlk – birgire Jan 10 '17 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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