Support Forum
Hello,
Before submitting this forum ticket, I went through the forum threads, I found some threads with some basic information but not directly related to what I am trying to achieve.
So here is what I want to achieve…
I have 2 custom post types “Companies” and “Reviews”.
Here is a link to a sample company single page https://meta.kioubizin.mu/company/test-company/
As you will see on this page, just below the title, I have 6 rating criteria and the star ratings of these fields are connected to hidden custom fields within the company custom fields as below:
review_availability
review_pricing
review_punctuality
review_quality
review_reliability
review_follow_up
Now, at the bottom of this page, I have a reviews section with the same review criteria, but these criteria are populated from the “Reviews” custom post type with these range (1 to 5) custom fields:
availability
pricing
punctuality
quality
reliability
follow-up_after_sales
I created a relationship between “Companies” and “Reviews”, if you click on the “Submit a Review” button just below the header rating summary, you will a popup that will open the review submission form (a MB Frontend Submission form).
Now what I want to achieve:
1. When someone submits a review, I want this review to be automatically assign to the company (its parent relationship) on the same page without the need for the user to select the company in the review form.
2. All the review criteria in the review form submission are required, when someone submits a review, let say we have 10 submitted reviews with an average rating of 4 for availability, 3 for pricing, 2 for punctuality, 3 for quality, 4 for reliability and 4 for follow-up, I want to be able to populate these average rating in the “Companies” hidden fields corresponding criteria so that average criteria is shown as summary just below the company’s title and users can click on the “View Reviews” button to see detailed reviews and ratings for the current company.
I am using Elementor as page builder because I am not too much used with the coding part, I have some knowledge of course that I can implement based on specific guidelines and template codes etc. same as I did for the “Opening Hours” by following this tutorial https://www.youtube.com/watch?v=Q6xb17yaXag but using a combination of MetaBox custom fields, MB Views and Elementor.
Something else I also need some help is to limit the number of words for the review content (editor) box as you can see, I added a test review with a very long paragraph, and I don’t want users to add such a long review.
Hello Jean,
1. You can use the action hook rwmb_frontend_after_process
and create a callback function to set the relationship between two objects by using the function MB_Relationships_API::add()
.
Please read more on the documentation
https://docs.metabox.io/extensions/mb-frontend-submission/#form-hooks
https://docs.metabox.io/extensions/mb-relationships/#add
And refer to this topic
https://support.metabox.io/topic/connecting-child-posts-to-a-parent-post-automatically/?swcfpc=1#post-35799
2. The star rating field should be set to required. Please read more on the documentation https://docs.metabox.io/field-settings/
3. And use the field validation to set the maximum number of characters input. Please read more on the documentation https://docs.metabox.io/validation/