In this tutorial, we’ll learn how to assign specific FAQs to show only for certain posts. For example, let’s say you have a Properties CPT with two types of properties: for sale and for rent. You want to display FAQs related to property sales only for properties listed for sale, and FAQs related to property rentals only for properties listed for rent. While this concept can be applied to many use cases, this tutorial will focus on this specific example to guide you step by step.
Creating Custom Post Type
First, we’ll need to create two custom post types: one for Properties Listing and another for FAQs. This will help us organize our property listings and FAQs separately, making everything more structured and easier to manage. If you’re new to creating custom fields, check out our tutorial: How to Create a Custom Post Type Using ACPT. It will guide you through the process step by step.
Creating Custom Fields
After creating the custom post types, we’ll also need to set up custom fields for both the Properties and FAQ custom posts. If you’re unsure how to create custom field groups or add fields, take a look at our tutorial on Creating Custom Fields for a detailed guide.
For the Properties CPT, we’ll need to add a Post (Multiple) Field. This is because we want to link multiple FAQs to each property on its single page.
Here’s how to do it:
- Add a new field and label it Related FAQ.
- Choose the Post (Multiple) Field type.
- Click on Advanced Options to specify which posts you want to fetch data from, set the post status, and configure other settings as needed.
Configure how posts are filtered and displayed in the dropdown/selector:
- Field Layout:
- Option: Only name or title
- Displays posts by their titles only (alternative: show featured images with title).
- Filter by Post Type:
- Option: FAQs
- Restrict selectable posts to the “FAQs” post type.
- Filter by Post Status:
- Option: Publish
- Only show published posts (exclude drafts or private posts).
- Filter by Taxonomy:
- Option: Select
- Filter posts by a taxonomy (e.g., only show FAQs tagged “Rent”).
- Note: You must first define the taxonomy and assign terms to posts.
After you create your custom fields and save everything, when you populate your custom post type (CPT) and want to add properties, your screen should look like the image shown below. Also, your post object should only display the FAQ that is published. This happens because we set our filter to show only published FAQs.
Now that you’ve completed all these steps, simply choose the FAQs that you want to add to that specific property and save your changes.
Displaying on the Frontend
To display your single property and show these related FAQs, go to Bricks > Templates and create a new template. Next, select ‘Single’ as the template type. After that, click ‘Edit with Bricks’ to design the layout you want for your single property.
After you design your layout, you should query the outer wrapper of your FAQ and connect it to your related FAQ post object custom field. Then we will use the dynamic values of our questions and answers since we use the FAQ’s for a custom post type (FAQ CPT) we use the questions as How to Assign Certain FAQs to Specific Posts using ACPT and Bricks and the answer as a custom field of {acpt_faq_faq-metabox_answer}.
Then, save the changes. Now, go to your properties and assign your related FAQ to each property listing you have. After that, check the frontend. Each property should now display the questions and answers you assigned by using the FAQ post object.
Using Conditional Logic
If no related FAQ is set, all FAQs will be shown. This ensures that our design stays intact and that each property will have FAQs, even if you or your client forget to add a related FAQ to a specific property.
First, duplicate the FAQ layout so you will have two FAQs showing on the page. Then, go to the one that has the related FAQ’s query parameters. Click on ‘Conditions’ to add a new condition.
Next, we will configure the All FAQ’s condition. This condition will ensure that even if a related FAQ is not assigned, the property will still display FAQs, keeping the design consistent and functional.
After you have set all of this up, everything should now work as expected. If a property has assigned Related FAQs, only those specific FAQs will be displayed. If no Related FAQs are assigned, then all the FAQs will be shown. This ensures that every property will have FAQs, whether or not specific ones are assigned.
Method (2)
In this section, we’ll explore an alternative method to approach the task. While the previous strategy works well in many cases, one of our ACPT community members highlighted a potential limitation: if you’re managing a large number of properties or a lengthy list of FAQs, the original approach might become less efficient over time.
Creating A Many-to-Many Bidirectional Relationship
Let’s start by setting up the foundation for this method. Here, we’ll create a many-to-many bidirectional relationship field to link FAQs CPT and Properties CPT. This setup allows you to assign FAQs to Properties while editing or creating either one giving you flexibility to manage connections in both directions.
FAQ Field Group
Head over to your Field Groups section, this is where all your custom fields are organized. From the list, identify and select the field group that’s linked to your FAQs
Once you’ve found it, click Edit to open its settings. This step is crucial because editing the correct field group ensures that any changes you make (like adding or adjusting fields) will automatically apply to all instances where this group is used.
- Add a New Field:
- In your FAQ field group, click Add Field.
- Choose any field type because ACPT needs two fields in different field groups that you want to connect. This is important for setting up your bidirectional relationship fields properly (I used a text field)
- Label It Clearly:
- Name the field something intuitive like “Related Properties”. This label will appear when editing FAQs and will use when we are querying in bricks UI.
After that, make sure to save your changes.
Property Field Group
We’ve built the first half of our bidirectional relationship field. Now, let’s complete the puzzle by creating the second required field in ACPT. This field will act as the ‘counterpart’ to the one we just made, ensuring FAQs and Properties can communicate.
- Navigate to Properties Field Groups:
- Head to the field group tied to Properties (Property field groups), Once you’ve found it, click Edit to open its settings
- Click Add Field and choose Relationship Field. This tells ACPT you’re creating a field to link entities (FAQs ↔ Properties).
Name this field something like “Related FAQs” to mirror the “Related Properties” field we created earlier. Consistency here makes the connection obvious.
Then under RELATED ENTITIES AND RELATIONSHIP, locate the “From” dropdown select Properties entity (the entity you’re currently editing). This defines where the relationship originates. Since we’re editing the Properties field group, the relationship starts here (Properties → FAQs).
then “To” dropdown select Select FAQs from the list. This defines what you’re linking to. Here, you’re connecting Properties (source) to FAQs (target).
Locate the Relationship dropdown, and select Many to Many – Bidirectional
Why This Matters:
- Many-to-Many: A single Property can link to multiple FAQs, and a single FAQ can link to multiple Properties.
- Bidirectional: Changes made on either side (Property or FAQ) automatically update the other.
Then at the “target file, select field box from the list” you will need to choose the metabox that is associated with the field we created in the FAQ field group FAQ Metabox
Locate the Target Field dropdown under the relationship settings. Then Select related-property (the existing relationship field in the FAQ entity).
Next, save the changes. Then, go and check the FAQ custom post type and the Properties CPT. The relationship field should be there and displayed as shown in the picture below.
Displaying on the frontend
Now that we’ve set up our many-to-many bidirectional relationship, let’s display it on the frontend. First, design your properties single layout using the method mentioned above. Then, decide where you want to add the FAQ section.
To query the relationship field, click on the FAQ wrapper and toggle on the query option. After that, select the appropriate query field.
In the query parameters, you’ll see [properties]-properties-metabox related-faqs and [faq]-faq-metabox related-property. These are the two fields we created and linked, and they function differently. If you’re in the properties template and want to query the relationship field, choose the first one. If you’re on the FAQ’s single page, select the second one.
While it may not be necessary to display the FAQ single page and its related properties in this case, you can do so if needed. However, it’s important to remember this for other use cases.