How to filter custom post by rating star

Question

First user fill this custom comment form.

first step

This is my meta_key i want that i want to fetch.
for every comment there are 10 rating.

meta_key

I want to make below rating filter.But don’t know how to start.

final output

This is what i tried yet.

add_action( 'comment_post', 'show_message_function', 10, 2 );

function show_message_function( $comment_ID, $comment_approved  ) {

    $comment = get_comment( $comment_ID );

    if( empty($comment) ) {
      return;
    }

    $post = get_post( $comment->comment_post_ID );

    $post_comments = get_comments( ['post_ID' => $post->ID ] ); 

    $meta_value = get_comment_meta($comment->comment_ID);

    d($post);

    // d($post_comments);
    d($meta_value);

    die;
}

function d($data) {
  echo '<pre>', print_r($data), '</pre>';
}

UPDATE:
I created a post meta and save it in updated rating average every time a comment is posted.

Now want to make a filter as shown in above image, when any user click on checkbox against number of stars data must be filtered , and show those custom posts have average = chosen number of stars.

0
inrsaurabh 3 years 0 Answers 62 views 0

Leave an answer