Display only those records in one CPT based on a bidirectional relationship field from other CPT

I hope someone can guide me through this:

I am using Bricks in anew project and use PODS for CPTs. The website is for a cleaning services company.

  • CPT#1: cleaning_service: info about each service + bidirectional relationship field (service_related_faq) pointing to CPT#2 + bidirectional field (service_related_cleaning_service_plan) pointing to CPT#3.
  • CPT#2: faq: Set of questions and answers + bidirectional relationship field (related_cleaning_service) pointing to CPT#1.
  • CPT#3: cleaning_service_plans: prices and what is included in each plan+ bidirectional relationship field (related_cleaning_service) pointing to CPT#1.
  • CPT#4: saving_coupons: coupons for special prices + bidirectional relationship field (related_cleaning_service) pointing to CPT#1.

The objective: show for each service its own information plus only the related FAQs (in an accordion element), Plans (in a loop grid), and coupons (in a loop grid) for the corresponding service.

The questions to you:

  • Is there a way to set up this with Bricks without programming? How should the query loop be set?
  • If not, what would be the code to make it happen? Where should it be pasted? How can I add this to the wish list/suggestions?

If you think you can help and need more information, please feel free to book an appointment at centrix.com and we’ll talk about it. I do appreciate your help!

Hey Oscar,

as Pods is not natively integrated you could use the custom query editor to fetch the posts from the bidirectional fields.

So if you’re in the single template for your cleaning service and want to fetch the related plans it could look something like this:

This is the code for you to copy as a starting point:

$pod = pods();
$related_plans = $pod->field( [
  // change to your relationship name
  'name' => 'plans',
  'output' => 'ids',
] );

return [
  'post_type' => 'plan',
  'post__in' => $related_plans,
];

Let me know if anything is unclear or if I can help any further.

Best,

André