Support

Account

Home Forums Front-end Issues Moving ACF between environments and acf_form($options)

Solved

Moving ACF between environments and acf_form($options)

  • If I use the export to PHP feature for a field group – how can I confirm what the ID is to use in the acf_form parameter field_groups ? Currently I have used the XML which generates a post ID in admin, but that can change between environments depending on other content created.

    The scenario I’m trying to do involves using a front-end form (for a CPT photo gallery) on a separate CPT event calendar. The filter acf/pre_save_post generates the new ID, an action tied to wp_enqueue_scripts to load JS that populates Event ID into hidden field.

    But the issue I have encountered was that I manually created the ACF form in dev and then in prod separately. The ACF Field Groups got different IDs – which would have also happened if I had used the export as XML. The field objects got different IDs which I use to pull event ID and photographer into gallery title – $_POST[“fields”][‘field_530ce8b2ddfcf’].

    I’ve included the PHP export snippet below, but unclear how to map its ID into the acf_form options attribute field_group given that it isn’t a post ID.

    
    if(function_exists("register_field_group"))
    {
    	register_field_group(array (
    		'id' => 'acf_photo-gallery-details',
    		'title' => 'Photo Gallery Details',
    		'fields' => array (
    			array (
    				'key' => 'field_530ce8b2ddfcf',
    				'label' => 'Event ID',
    				'name' => 'pgalleryEventID',
    				'type' => 'text',
    				'required' => 1,
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_530ce8c0ddfd0',
    				'label' => 'Photographer Name',
    				'name' => 'pgalleryPhotographer',
    				'type' => 'text',
    				'required' => 1,
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_530ce8d9ddfd1',
    				'label' => 'Photographer Email',
    				'name' => 'pgalleryEmail',
    				'type' => 'text',
    				'required' => 1,
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_530ce8eaddfd2',
    				'label' => 'Photos',
    				'name' => 'pgalleryPhotos',
    				'type' => 'gallery',
    				'required' => 1,
    				'preview_size' => 'thumbnail',
    				'library' => 'all',
    			),
    		),
    		'location' => array (
    			array (
    				array (
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'pgallery',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    			),
    		),
    		'options' => array (
    			'position' => 'normal',
    			'layout' => 'no_box',
    			'hide_on_screen' => array (
    			),
    		),
    		'menu_order' => 0,
    	));
    }
    
    

    http://www.advancedcustomfields.com/resources/tutorials/creating-a-front-end-form/

  • And the code (which doesn’t display my form) on template:

    
    $args = array('post_id' => 'new', 'field_groups' => array('acf_photo-gallery-details'));
    						
    acf_form( $args );
    

    In other templates I do have the call to acf_head(). I do see the Update button display and when inspecting source the rest of the hidden fields and form. But no actual fields.

  • Solved. I had the register_field_group in plugin tied to admin_init instead of init.

    As a future enhancement to the plugin, I might suggest a section to the admin page that lists field groupings which are created via plugin / theme for reference.

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

The topic ‘Moving ACF between environments and acf_form($options)’ is closed to new replies.