Support

Account

Home Forums ACF PRO PHP import

Solved

PHP import

  • 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;
    
  • im getting:

    Function exists

  • 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.

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

You must be logged in to reply to this topic.