ACF Pro relationship between two CPT's

Hello,

I have created a relationship between two CPT’s - Products and Materials.

Products contain normal custom fields such as product name, price, description etc. and a relationship-field (Post-Object) filtered by Materials post type.
Materials contain multiple fields such as material name, id, description etc.
One material can be related to multiple products, but a product can only be related to one material.

My issue:
I have created a layout for Products and I’m able to pull in the information from the Materials CPT. My problem is that it always pulls the latest added material and not the related material.

How everything is set up:

I’ve got a Div (Material info) set as both a Provider (Query string:

post_type=materialer&posts_per_page=1&offset=0&ignore_sticky_posts=1&post_not_in%5B0%5D={{dc:looper:item}}

) and as Consumer.

Inside the Div I got 3 text-fields

{{dc:acf:post_field field=“materiale_id”}}
{{dc:acf:post_field field=“materiale_navn”}}
{{dc:acf:post_field field=“materiale_beskrivelse”}}

I’m pretty new to query strings so it might be a rookie mistake, but I just can’t seem to figure it out.

PS: The CPT’s are in Danish so Products is called Produkter and Materials is called Materialer.

Hello Morten,

Thanks for writing in!

Your WP Query is not related to the product itself. You should be using this instead:
post_type=materialer&p={{dc:acf:post_field field="materiale"}}

In this query, you are trying to get the Material custom post type that is being assigned to the product based on the ACF field.

Kindly let us know how it goes.

Hello ruenel,

Works perfect! Thanks!
Premium support as always :smiley:!

Could you tell me what the ‘p’ in the string stands for?

Hey Morten,

The p parameter stands for the post ID. You can check the link below for reference.

Hope that helps.

Hey marc_a,

Thank you for clarifying!
I’ll have a look at the docs.

Hey Morten,

You’re welcome! If you have any other concerns or clarifications regarding our theme features, feel free to open up a new thread.

Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.