Home › Forums › ACF PRO › Add filter on the relationship field inside a group › Reply To: Add filter on the relationship field inside a group
To be honest, I don’t know exactly without testing. I do know that the field name is not what you would expect when calls fires the hook. It does have to do with the hierarchy of the field. I would expect your first example to work, but, it the group field also a sub field of some other field? Is it part of a cloned fields?
The only way to find out is to create a filter for all fields and output it to see what the name is.
// all fields filter
add_filter('acf/prepare_field', 'output_field_object');
function output_field_object($field) {
echo '<pre>'; print_r($field); echo '</pre>';
return $field;
}
There have been times when I needed to use the field name and I have had to create my filter for all fields and then use ‘strpos()` to test the field name or even the field key to see if it is the field I need to filter. There is always some logic to it as to why the name is what it is for the filter.
But for the most part, whenever I am dealing with filtering a sub field of any kind I just use the field key.
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!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.