The priority doesn’t work because it appears the actual field is rendered using this action hook:
do_action( "acf/render_field/type={$field['type']}", $field );
The action hook do_action( "acf/render_field", $field );
appears before the one mentioned above. In order for priority to work, you need to use the 2nd hook using the field type. Hope that helps.
Ok, I think I came up with a working solution. Here’s the code:
https://gist.github.com/solepixel/e8f09b9ba781502f893274ff8bf6dcf1
Basically, each settings page needs a menu_slug and that menu_slug should have somewhat of a consistent naming convention to identify settings pages with common field groups.
Then, the settings page also needs a way of identifying the unique values, in my case they’re associated with Post Type Archives, so I’m using the Post Type.
I make sure the screen matches one of the desired settings pages, then I prefix the field with the Post Type, so I can grab the specific field setting in my theme. Hope that helps someone.
I would be curious to see a solution where duplicating the fields isn’t required. Sometimes post archive templates look the same, but they are custom and each require unique fields/settings. I may have 20 CPT Archives that all look the same and would be neat if the option storage could be connected with page it’s on. So for a field called “_description”, the slug of the page could be stored with it like “_staff_settings_description”.
I’ve tried modifying the field names to just post values under different fields, but ACF must be looking up the “option_name” value with the field ID and always store it under that name. I’m looking for this code to see if I can modify it as well.
@zaccety I think I figured out it had something to do with the placement of the function call. See here: https://github.com/solepixel/acf-modules/blob/master/modules/icon-blocks.php#L242
Notice that it’s outside “have_rows”. I’m pretty sure that’s all I needed to do and it returns the correct amount.
This doesn’t seem to work inside a flexible content loop. The return from get_field() is NULL. I tried get_sub_field() and that returns false. Any suggestions?
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.