ACF Related Portfolio Item

I want to create a relation via ACF for the portfolio items and display them as linked after the content.

For this I have created a relational field in ACF and linked the items accordingly. But although I have selected Object in the return value, I get only post ID in the Looper, with which I of course can not really do anything.

screenshot 1

screenshot 3

Looper Consumer Debug:

screenshot

Shouldn’t be that an object with the post data?

And is it possible to do a reverse relationship lookup as mentioned in the acf documentary for the related portfolio items?

Ok, i think i figured it out that i have to use the ACF Dynamic functionality. I posted that for other’s too:

correct Looper provider should look like this:
screenshot 1

But i think about my second question, this doesn’t work for revers lookup related posts.

Hey @Regnalf,

Thanks for reaching out!

We’re not quite sure what you mean by reverse lookup related posts, would you mind sharing with detailed explanation?

Cheers!

Gladly. As far as I can see, ACF has two fields that are eligible. The “Post object field” and the “Relationship field”.

Both actually return the same result, which is the linked posts. While the “Post Object” is obviously meant to be a one-dimensional link, i.e. simply return the entered posts, I see the “Relationship Field” as a link between two posts.

So when I create a link between two items in a portfolio item, I expect the linked item to also link back to the current one. But at the moment I don’t see any added value for the “Relationship Field” compared to the “Post Object Field” because it also only creates a one-dimensional and not a bidirectional link.

I did find a tutorial in the ACF documentation on how to program this reverse connection myself, but I think this field should be able to do that from the start!

Basically, what I want to achieve is a specific definition of related posts. The WordPress standard logic is not suitable for an exact connection of related posts.

Seems not to be in core, but i found this:

Update: If you want this dynamically for all relationship fields, use this extra filter functionality:

add_action ('init', 'ACF_set_filter_bidirectional_relationship_update');
function ACF_set_filter_bidirectional_relationship_update ()
{

$q_acf_fields = new WP_Query (array (	'post_type' => 'acf-field', 'posts_per_page'	=> -1) );
									  
if ( $q_acf_fields->have_posts() )
{
	foreach ($q_acf_fields->posts as $acf_field)
	{
		
		$field_settings = unserialize($acf_field->post_content);
		
		if ($field_settings['type'] == 'relationship')
		{
			add_filter ('acf/update_value/name=' . $acf_field->post_excerpt, 'ACF_bidirectional_relationship_update', 10, 3);
		}
	}
}

}

Hey @Regnalf,

Yes, you need to set up bidirectional in order for both data to be shown vice versa, and were glad that you’re able to find an answer to your question. Another example is on this thread.

Cheers!

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