Hello,
I want to edit some codes written by another developer, actually I want to edit and add some new fields to my customer blog which use acf plugin, there is nothing in acf page in wordpress admin, so I searched in template files and I findout the fields I want to change is in a file and inside that file there is acf_add_local_field_group function with many arrays, I want to add a field with condition (when a choice menu selected this field should appear) I use this code to make it done :
'conditional_logic' => array(
array(
array(
'field' => 'field_5ecccf8f46aa8',
'operator' => '==',
'value' => 'selected',
),
),
),
but for some reason it didn’t depend on that condition and the menu shows in any condition, anyone can help me ? is there any other file should I edit in order to set this filed with this condition ? Can I import these arrays in graphical acf interface and edit them in dashboard ?
Here is whole code for this field :
array(
'key' => 'field_manategh',
'label' => 'مناطق',
'name' => 'manategh',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5ecccf8f46aa8',
'operator' => '==',
'value' => 'selected',
),
),
),
'wrapper' => array(
'width' => '25',
'class' => 'wid25',
'id' => '',
),
'choices' => array(
'منظقه 1' => 'منظقه 1',
'منظقه 2' => 'منظقه 2',
'منظقه 3' => 'منظقه 3',
'منظقه 4' => 'منظقه 4',
'منظقه 5' => 'منظقه 5',
'منظقه 6' => 'منظقه 6',
'منظقه 7' => 'منظقه 7',
'منظقه 8' => 'منظقه 8',
'منظقه 9' => 'منظقه 9',
'منظقه 10' => 'منظقه 10',
),
'default_value' => false,
'allow_null' => 0,
'multiple' => 0,
'ui' => 0,
'return_format' => 'value',
'ajax' => 0,
'placeholder' => '',
),
The best advice I can give you is to create a temporary field group that contains a field with the same options choices as your choice field and a copy of your conditional field and then export this to PHP. Look at the code that is generated and then mimic that to add your new field to the existing group. Then you can delete the temporary field group.
I get your point, thanks for your reply. but the problem is nothing shows in plugin menu in graphical interface, so when I want to create new field it does not show existing filed so I can’t create a condition because I can’t select anything… its empty… do you have any suggestion how to solve this ?
I think you’ve missed my point.
No, the fields do not appear in the admin because they have been moved to PHP.
I think your conditional logic is not correct, but I cannot tell from what you’ve provided why it is incorrect.
You are going to create a temporary field group.
Then you are going to create a field in this group that exactly mimics the field you are referring to here
when a choice menu selected this field should appear
Including all of the values and settings for this field.
Then you are going to create the field you want conditional on this field and set it up so that it works properly.
Then you are going to export this group to php and you’re going to copy your new field into the PHP file where you want the new field to appear and you are going to alter the field key in the conditional logic of your new field to match the old field that you want the new field to be conditional on.
Once you get all of this done and your new field is working then you will delete the temporary group that you created.
You must be logged in to reply to this topic.
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.