Support

Account

Forum Replies Created

  • 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)

Viewing 3 posts - 1 through 3 (of 3 total)