Support Forum
Support › Meta Box AIO › How to configure metabox for this scenario?
Chao
I have a FAQ CPT with FAQs Post:
FAQs about A
FAQs about B
etc.
Each FAQ post has a metabox field group with 5 x questions and answers about the faq post. As per screenshot
I then want to add the questions and answers to a loop on a template page. I want to target the correct FAQ post with the correct questions and answers based on a custom field on the page where the template is used?
What is the best way to achieve this?
Thanks
Hi Michael,
It looks like you are using a cloneable group with subfields Question and Answer. The group is used to store data, not for querying, so it is very complicated to query posts FAQ by subfield value. Please read more here https://metabox.io/create-group-of-custom-fields-with-meta-box-group/?swcfpc=1#how-does-the-meta-box-group-save-data
If you want to query posts by the custom field value (top field), please follow this article https://metabox.io/get-posts-by-custom-fields-in-wordpress
Chao Long,
Cam on for your reply.
Ah, I will not use the cloneable group to query; I will use Bricks builder to query the group, but I want to know how to use the custom field on the page to use the FAQ post that has the right question and answers.
For example, I have a template set up and the cloneable group FAQ Question & Answer selected with the subfields in a nestable repeater field (accordion, tabs, etc). On the individual pages where the template is applied, I have a custom field with the value of 'plumber' so I want it to choose the FAQ post in the FAQ CPT, which I have used to answer Plumber questions & answers.
So if I go to the page about plumbers, then the question and answers on the page will be about plumbers.
If I go to a page about Electricians, then the question and answers will be about Electricians.
But not sure how to connect the two?
Many thanks
Michael
Hi Michael,
I do not see the benefit when you add more Questions and Answers on a FAQ post but just show one on the frontend.
If the Questions and Answers are related to the FAQ post, you can just show all Q&A on the frontend with the code by following the documentation https://docs.metabox.io/extensions/meta-box-group/
I think Bricks builder will not help in this case because it will not work with the cloneable group, you can try to use Elementor or Oxygen builder.
If you still want to create more Q&As and show one or some on the frontend, you can try to create a checkbox field and a sample label like "Show on the frontend". Then create an if statement to check this field value before outputting the Q&A.
https://docs.metabox.io/fields/checkbox/
Chao Long,
I do not want to show only one of the Questions and Answers, I want to show the whole 5 Question and answer subfields from the fact post.
But I will have many FAQ Posts, One FAq post with 5 questions about plumbing, one Faq post that has 5 questions about electrician, One faq post that has 5 questions about gas heating.
One way to do it would be to add the Question and answer to every page instead of using a FAQ CPT. But because I have ten pages on electricans, 10 pages on plumbing, and 10 pages on gas heating, etc. Would mean I would have to copy and paste it 30 or 40 times. Instead, I would rather have the FAQs for each service have their own FAQ post, so I only have to add them to the site once and then query that Faq post using a custom field that is set on the page.
P.s. Bricks does support cloneable groups.
The only part I do not know how to configure is how the group is connected to the page by the value I enter in the custom field. Do I do this via a relationship or?
I hope that makes sense?
Many thanks Long
Hi Michael,
Thanks for your additional information.
Ok, so in this case, you can use the extension MB Relationships to create a relationship between the page and FAQ post type. When editing the page you can set the connection from a page to many FAQs as you want.
Here is an example that is similar to this case https://metabox.io/mb-views-how-to-display-relationships/