Create Review functions creates multiple reviews
-
Hello,
Here’s the scenario.
I’ve added custom field to my rating form and I want to dynamically create review entry every time a form is submitted. The dynamic review entry is specific to a certain category/term and its rating value is base on the submitted rating of the custom field.
I have the following code
add_action('site-reviews/review/created', function ($review, $command) { $overallR_val = $review->rating; $qualityR_val = $review->custom->quality_rating; $serviceR_val = $review->custom->service_rating; $sustainabilityR_val = $review->custom->sustainability_rating; $assigned_post_id = $command->assigned_posts[0]; $author_user = $review->author; $author_email = $review->email; $author_id = $review->author_id; $date = $review->date; $ip_address = $review->ip_address; if (function_exists('glsr_create_review')) { $review = glsr_create_review([ 'rating' => $qualityR_val, 'name' => $author_user, 'email' => $author_email, 'date' => $date, 'assigned_users' => $author_id, 'assigned_posts' => $assigned_post_id, 'assigned_terms' => 139, 'ip_address' => $ip_address, 'quality_rating' => $qualityR_val, 'service_rating' => $serviceR_val, 'sustainability_rating' => $sustainabilityR_val ]); } // log data glsr_log($overallR_val); glsr_log($qualityR_val); glsr_log($serviceR_val); glsr_log($sustainabilityR_val); }, 10, 2);
but it seems like
glsr_create_review
is also triggering thesite-reviews/review/created
causing infinite loop that creates multiple review entry.What will be the best approach for the said requirements?
Thank you in advance for the help
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Create Review functions creates multiple reviews’ is closed to new replies.