Metabox relationships: show data from one CPT when looping a related CPT. Is this possible with Bricks?

Hello! :blush:

I have two CPTs: States and Houses. One State can have multiple Houses.

On the homepage, I need to create a query loop with all the Houses available, regardless of the State they are in. BUT, I need to show in the card a tag indicating the State related to each House.

I have created the CPTs with Metabox, and also created a Relationship between States > Houses.

But now comes the tricky part. Is there any way to…

  1. Create a grid of cards with all the Houses.
  2. For each House, look for the State that the House is related.
  3. Show the Post Title of the State in each House Card?

Any ideas? Is it possible to do it with the built-in controls of the Query interface in Bricks?

Thank you very much! :slightly_smiling_face:

with loop query editor anything possible.

image

without query editor yes most of the relational loops are possible in some degree
it really depends on what you need…

Is it possible to replace a static value in the Query Editor with dynamic data?

For example:

return [
  'post_type' => 'page',
  'page_id' => {value from custom field}
];

play with it and practice a lot :slight_smile:

Wait, I can’t believe I missed that!!!

1 Like

Finally, I found a solution without the need to write PHP!

Having CPT A and CPT B, and being those related with Metabox Relationships:

  1. Create a main loop for the CPT A.
  2. Inside the loop, create another loop querying the relationship between CPT A and CPT B.
  3. Then, in this secondary loop, you can call for dynamic data from the related CPT B.

I hope this helps to someone facing the same scenario in the future :blush:

3 Likes