Skip Navigation

[Resolved] Integrate a second star rating to existing rating system

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 1 year, 1 month ago.

Assisted by: Waqar.

Author
Posts
#2667095

Dear Toolset team,

you supported me already by setting up a rating system where users can rate a company – this works perfectly fine – thank you for this!

Now, additionally I want to integrate to the existing company rating form a rating to rate the employer. So the idea is that a user simply can fill in in the known company rating form besides the company rating the employer rating. So for achieving this I added to the existing CPT “company” two fields “employer-ratings-average” and “employer-ratings-total” and to the CPT company-review the field “employer-rating”. The function.php code I enhanced by this new fields, see here:

/**
* Route child employer ratings to parent ratings
*/
function update_company_review($post_id, $form_data) {
// if specific form, change ID to the CRED "Review" ID
if ($form_data['id'] == 50) {
// Get ID of Company Being Reviewed
$parent_post = $_POST['@company-company-review_parent'];

$reviews = toolset_get_related_posts($parent_post,'company-company-review','parent',999,0,array(),'post_object','child');

$sum = 0;
$num = 0;
foreach ($reviews as $review) {
$ratings = get_post_meta($review->ID, 'wpcf-employer-rating', true);
if ($ratings) {
$sum += $ratings;
$num++;
}
}
$average = ($num > 0) ? $sum / $num : 0;

// Rundung auf die nächste Zehntelstelle (0,1)
$res = round($average, 1);

update_post_meta($parent_post, 'wpcf-employer-ratings-average', $res);
update_post_meta($parent_post, 'wpcf-employer-ratings-total', $num);
}
}
add_action('cred_submit_complete', 'update_company_review', 10, 2);

But when I try to save it it shows me an error. Could you please have a look on it and tell me how to fix this?

Thank you and best wishes
Andreas

#2667105

Hi Andreas,

Thank you for contacting us and I'd be happy to assist.

Did you checked the server's error logs for the detailed error?

If not, I'll recommend temporarily enabling WordPress debugging and then checking the server's error log for detailed error/warning.
( ref: https://wordpress.org/documentation/article/debugging-in-wordpress/ )

If there are no details, you're welcome to share temporary admin login details, along with the exact steps that you performed to make changes to the theme's "functions.php" file.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

regards,
Waqar

#2667445

Hi Waqar,

I could solve my issue now by my own by doing a bit trial and error.

Nevertheless many thanks
Andreas