Hi Waqar,
yes this worked well, thank you 🙂
Now I also tried to integrate the review-moderating function that "Company ratings average" and "Company ratings total" only get updated after I approved a new review. Because without this additional function the two fields also get updated before I approve a review. I found in this post
https://toolset.com/forums/topic/parent-child-review-ratings-system/
the necessary code and changed it to my slugs. But I could not even store the code in my function.php. Can you also have a look on this and tell me where the error is?
I tried to add the following code:
function func_on_review_publish($new_status, $old_status, $post) {
if($old_status=='pending' and $new_status=='publish') {
$parent_id = toolset_get_related_post($post->ID,'company-company-review');
// get parent total rating
$ratings = get_post_meta( $parent_id, 'wpcf-company-rating',true);
if(empty($ratings)) {
$ratings = 1;
// get current rating
$avg = get_post_meta($post->ID, 'wpcf-ratings',true);
}else{
$old_ratings = $ratings;
$avg = get_post_meta( $parent_id, 'wpcf-company-ratings-average',true);
$ratings = $ratings+1;
$current_rating = get_post_meta($post->ID, 'wpcf-ratings',true);
$avg = ((($avg*$old_ratings) + $current_rating)/$ratings);
}
update_post_meta( $parent_id, 'wpcf-average-rating', $avg );
update_post_meta( $parent_id, 'wpcf-company-ratings-total', $ratings );
}
}
add_action( 'transition_post_status', 'func_on_review_publish', 10, 3 );