Hi,
im using latest version of Pro ACF. I used setting to export my preset.
But when i use code i received from export and put it in functions.php it’s not creating my field.
code is here
if( function_exists('acf_add_local_field_group') ):
/**
* Adds google analytics code
*/
acf_add_local_field_group(array (
'key' => 'group_5716188715641',
'title' => 'Google Analytics',
'fields' => array (
array (
'key' => 'field_571618931eb0b',
'label' => 'Google Analytics',
'name' => 'googleAnalytics',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
),
'location' => array (
array (
array (
'param' => 'options_page',
'operator' => '==',
'value' => 'acf-options-google-analytics',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
/**
* Add SEO - title and description fields
*/
acf_add_local_field_group(array (
'key' => 'group_55487eece85a8',
'title' => 'SEO',
'fields' => array (
array (
'key' => 'field_55487ef08c957',
'label' => 'Titulek stránky',
'name' => 'page_title',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_55487f148c958',
'label' => 'Popis stránky',
'name' => 'page_description',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_571e01d6e5ae7',
'label' => 'Indexace',
'name' => 'robots',
'type' => 'radio',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array (
'index,follow' => 'index,follow',
'index,nofollow' => 'index,nofollow',
'noindex,follow' => 'noindex,follow',
'noindex,nofollow' => 'noindex,nofollow',
),
'other_choice' => 0,
'save_other_choice' => 0,
'default_value' => 'index,follow',
'layout' => 'vertical',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'page',
),
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
endif;
Can you please help me? 🙂
Thanks
Where are you putting this code? In your theme or somewhere else. Also, how is ACF installed, normally or in the theme?
Core is inside function.php in my theme.
Acf is installed normaly in plugins
Some debugging, because, well, that’s odd
put this just before you try to create the field groups, load a page on the site and see what happens then immediately remove the code. The reason is that this will cause other errors and we’re just trying to find out if the function exists when you are trying to use it.
if (function_exists('acf_add_local_field_group')) {
echo 'function exists';
} else {
echo 'function does not exist';
}
die;
Are both field groups not appearing or just one of them is not appearing?
I just took a close look at the location rules on the second one and the values there indicate that they are
Post Type
is equal to
Post
AND
Post Type
is equal to
Page
which is impossible.
Hi John,
thanks for help, i think i figured out where was the problem.
I thought that this php import will create the ACF in admin. So i can edit them etc, but it will only show them on their location. My fail. I’ll use JSON.
Thanks for your time, i appreciate it!
Boris
ah, that explains it. I thought that the fields were not showing up on the posts and pages. Yes, you’re correct. If you want to be able to edit them then you need to import them using ACF and not use PHP.
The topic ‘PHP import’ is closed to new replies.
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.