Support

Account

Home Forums ACF PRO Conditional Logic Issue w/ PHP Generated Field Groups

Solving

Conditional Logic Issue w/ PHP Generated Field Groups

  • When adding a field group via php code, I have instances where the conditional logic for specific fields does not work. I have not tested/checked all instances, but I have noticed this in a couple of many possible locations.

    In context: In a multisite installation, I use the main blog to create field groups for all other sub-sites, then I add the field groups through a mu_plugin and function that excludes the main blog.

    For the main blog, where the field groups and fields are created using the ACF UI, the conditional logic works fine. On the subsites where the php code is generating the field groups, the conditional logic for specific fields is broken. It breaks gracefully though, i.e. the fields all show by default.

    Just Reporting, Thanks for the continued hard work,
    JW

  • Hi @jwss76

    Thanks for the bug report. The only change I can think of is that conditional logic can now be grouped, so perhaps the compatibility script is not working as expected.

    Can you please post your field group php so I can tes the conditional logic?
    You can remove any data which is not relevant / private.

    Cheers
    E

  • Here’s the php export for two fields where the conditional logic is not working. I have removed several additional options from the choices array on the first field for brevity.

    array (
    	'key' => 'field_538f375f143cb',
    	'label' => 'Show Related Posts',
    	'name' => 'tmv_related_posts',
    	'prefix' => '',
    	'type' => 'select',
    	'instructions' => '',
    	'required' => 0,
    	'conditional_logic' => 0,
    	'choices' => array (
    		'none' => 'Do not show related posts.',
    		'category' => 'Show posts from Category.',
    		),
    	'default_value' => array (
    		'none' => 'Do not show related posts.',
    	),
    	'allow_null' => 0,
    	'multiple' => 0,
    	'ui' => 0,
    	'ajax' => 0,
    	'placeholder' => '',
    	'disabled' => 0,
    	'readonly' => 0,
    	),
    array (
    	'key' => 'field_538f4d2c3134b',
    	'label' => 'Related Category',
    	'name' => 'related_category',
    	'prefix' => '',
    	'type' => 'taxonomy',
    	'instructions' => '',
    	'required' => 0,
    	'conditional_logic' => array (
    		array (
    			array (
    			'field' => 'field_538f375f143cb',
    			'operator' => '==',
    			'value' => 'category',
    			),
    		),
    	),
    	'taxonomy' => 'category',
    	'field_type' => 'select',
    	'allow_null' => 1,
    	'load_save_terms' => 0,
    	'return_format' => 'id',
    	'multiple' => 0,
    	),
    

    Happy to provide whatever else you need if that isn’t enough.
    JW

  • Hi @jwss76

    Thanks for the exported fields. I’ve just added these to a local site, and they work great.

    I wonder if the issue is due to the multi-site setup you are using.

    Do you see any JS errors on the page where the conditional logic doesn’t work?

    Thanks
    E

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

You must be logged in to reply to this topic.