New project with only the ACF plugin (PRO) installed (5.10.2).
I put this inside functions.php (generated by ACF and then modified to use the field key inside the conditional_logic array) :
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_616de148bf2ce',
'title' => 'page after title',
'fields' => array(
array(
'key' => 'field_616de15b4155f',
'label' => 'Field in after-title group',
'name' => 'test',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'page',
),
),
),
'menu_order' => 0,
'position' => 'acf_after_title',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
acf_add_local_field_group(array(
'key' => 'group_616de1da31d45',
'title' => 'page normal',
'fields' => array(
array(
'key' => 'field_616de1eb45ead',
'label' => 'Field in normal group',
'name' => 'hiding',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => [
[
[
'field' => 'field_616de15b4155f',
'operator' => '!=',
'value' => 'test'
]
]
],
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'page',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
I can see both fields on the page, but when I type “test” into the first one (inside the after-title group), nothing happens (the second field inside the normal group should disappear).
BTW : thank you for your time ! It is really appreciated
Alright I’ll try that, I didn’t know there was a prerequisite like that, I shipped about 20 projects without those prefixes and never had any issue (never tried to do conditions across field-groups though).
I’ll let you know, thank you !
Oh ok sorry, those actually are field keys, I’m setting them programmatically when defining the fields by code. They are unique in the context of the post-type.
I don’t get it, isn’t that already what I’m doing since we can see in the last screenshot the same value inside the field’s data-key (in red) and the other field’s data-conditions (in blue) ?
Hi !
I’m trying to do the exact same thing and have setup the conditional field keys inside my code.
Everything is working as expected inside the same field-group but the conditional field is not taken into account by the field inside the second field-group.
Could you help please ?
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.