I have managed to make my own custom comment rating system - that was working fine until now. I got an idea: why not add star rating to individual comments? I thought it would be easy as I have already added a custom rating field in comment - through filter that is ..
add_action( 'comment_form_logged_in_after', 'additional_fields' );
add_action( 'comment_form_after_fields', 'additional_fields' );
function additional_fields ($below) {
$ratsec = '<p class="comment-form-rating">'.
'<label for="rating">'. __('Rating') . '<span class="required">*</span></label>
<span class="commentratingbox">';
//Current rating scale is 1 to 5. If you want the scale to be 1 to 10, then set the value of $i to 10.
for( $i=1; $i <= 5; $i++ )
$ratsec .= '<span class="commentrating"><input type="radio" name="rating" id="rating" value="'. $i .'"/>'. $i .'</span>';
$ratsec .= '</span></p>';
$below = $below .$ratsec;
return $below;
}
But when I change things and add this filter
add_filter( 'comment_text', 'additional_fields' );
it starts showing the radio button in every comment just below the user text - but how to submit them? As along with comment you have submit button ?
My first Question is: How I can make the rating submit ?
My Second Question is: If I vote 3 star for "comment number one" will it affect all the comments or just the one I voted? I am confused how to make connection between them.
I was using comment meta data to save the data that was ...
add_action( 'comment_post', 'save_comment_meta_data' );
function save_comment_meta_data( $comment_id ) {
if ( ( isset( $_POST['rating'] ) ) && ( $_POST['rating'] != '') )
$rating = wp_filter_nohtml_kses($_POST['rating']);
add_comment_meta( $comment_id, 'rating', $rating );
}
Now the Code is completely changed How will I save the data in comment meta data to make it show on the front end ? What Modifications are required in the above action ? Plus now using the perfect method explained below by @s_ha_dum -- How will I store this data according to comment id ?