Home › Forums › Backend Issues (wp-admin) › Using acf/fields/relationship/result on ACF Block
I want to add some information to the title of a relationship field that resides in several ACF Blocks. The field is initially created in a field group called “Media” and this field is then cloned to different Blocks. It sometimes is nested in a group and sometimes it’s on the top level of the block.
The title of the field is ‘download_post_object’. Is there some way to globally apply the acf/fields/relationship/result
filter to all the occurrences of this field throughout the blocks? It seems like the filter is using a $post->ID
argument when selecting the field that should be modified, but in my example I would simply like to apply the filter on all occurrences. Or can I in some way target the block instead of the post for this filter?
This should have nothing to do with blocks. Your field name is likely changing because it is cloned and may sometimes be a sub field and sometimes not.
I would use the generic filter hook acf/fields/post_object/result
(no key or name). and then check the field name in my filter something like
if (strpos($field['name'], 'download_post_object') === false) {
return;
}
You may also be able to do this by using the field key variant, but depending on how the field is cloned the field key might also be changed when ACF runs these filters, I’m not sure.
Thank you! That seems to work!
Is there any way to echo fields from the posts listed in the relationship field? My idea is to output a field called “type” that lives within the post listed. So the label in the relationship field would be:
Post title > Type field
To be exact, the posts listed in the relationship field is of a custom post type that has this “type” ACF field added to them.
If you are talking about adjusting the same filter….
If this field is in a block, then I don’t know the answer, I do not work with the block editor.
ACF passes the post ID for each post being shown, normally you would just
$text .= ' - '.get_field('type', $post_id);
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.