I’m trying to do something similar to this. My code runs across different environments, and in each environment, the page I’m trying to set as a page parent location rule will probably have a different ID. So rather than having to manage that all over the place, I’d rather run a filter to alter the location rules. I have this going to grab the ID of the page by its path. And it seems to actually properly alter the location rules, but it doesn’t actually affect display in the admin screens. I feel like I’m doing something wrong, but I can’t quite put my finger on it.
add_filter('acf/load_field_groups', 'add_page_parent_rule');
function add_page_parent_rule($field_groups) {
$parent_page = get_page_by_path('path/to/parent/page');
foreach ($field_groups as &$field_group) {
if ($field_group['key'] === 'group_6983f5557e555') {
if (isset($field_group['location'][0])) {
$field_group['location'][0][] = array(
'param' => 'page_parent',
'operator' => '==',
'value' => (string) $parent_page->ID,
);
}
}
}
return $field_groups;
}
So I’m hooking into this as well and the ONLY way it seems to work is with "acf/load_field/type=message" as the filter. problem is then the definition of the field in the acf-field-group post gets altered as well. this is what I’ve got going on and it works:
// Allow for shortcodes in messages
function acf_load_field_message($field ) {
$type = get_post_type();
if ($type !== "acf-field-group") {
$field['message'] = do_shortcode($field['message']);
}
return $field;
}
add_filter('acf/load_field/type=message', 'acf_load_field_message', 10, 3);
It seems a little fragile and inelegant. Thoughts?
I was seeing this as well then i realized that i had totally forgotten to add any sub fields to the repeater in the field group. Added one and was on my way. (Version 5.3.3.2)
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.