Support

Account

Home Forums Backend Issues (wp-admin) Dynamic Custom Location

Solving

Dynamic Custom Location

  • Good Morning,

    I am trying to add a custom location to my ACF group that is dynamic.
    I’ve tried through the following filters acf/load_field_group and validate_field_group but can’t get them to work correctly.
    I have the ACFs exported in a php.
    I know that I can edit the file directly, but I want to know if there is any other alternative.

    Thanks a lot.

  • You can either use tha acf/validate_field_group filter or use PHP to dynamically generate the “location” settings for a field group. If you export a field group to PHP and examine the location array you can use this as an example of what needs to be done.

  • Thank you, I added this filter with the conditions and it all works properly.

    add_filter( 'acf/validate_field_group', 'add_custom_location_dynamic', 10, 1 );
    function add_custom_location_dynamic( $field_group ) {
    	if ( $field_group['key'] == 'group_5e998df494b16' && isset( $field_group['local'] ) && $field_group['local'] == 'php' ) {
    		$field_group['location'][0][] = array(
    			'param'    => 'page',
    			'operator' => '!=',
    			'value'    => get_field( 'custom_page', 'options' ),
    		);
    	}
    }

    Do you think I can improve it or do you have any more suggestions?
    Thank you!

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

You must be logged in to reply to this topic.