Support

Account

Home Forums Bug Reports array_merge error in API when using acf_form new_post

Unread

array_merge error in API when using acf_form new_post

  • It looks like sometime recently a new parameter was added to the acf_form() function called ‘new_post’ which allows the input of an array of parameters that match up to wp_update_post().

    This is GREAT!

    However, when I use this functionality I get this error while debugging:

    “Warning: array_merge(): Argument #1 is not an array in /home4/cummings/public_html/wordpress/wp-content/plugins/advanced-custom-fields/core/api.php on line 1185”

    When I look at that section of the API I notice that it is the defaults array for the acf_form() options, however it does NOT include a default for the ‘new_post’ parameter. If I add ‘new_post’ => array(), to that array, the error disappears.

    Original ACF API code:

    	// defaults
    	$defaults = array(
    		'post_id' => false,
    		'field_groups' => array(),
    		'form' => true,
    		'form_attributes' => array(
    			'id' => 'post',
    			'class' => '',
    			'action' => '',
    			'method' => 'post',
    		),
    		'return' => add_query_arg( 'updated', 'true', get_permalink() ),
    		'html_before_fields' => '',
    		'html_after_fields' => '',
    		'submit_value' => __("Update", 'acf'),
    		'updated_message' => __("Post updated", 'acf'), 
    	);

    My version:

    	// defaults
    	$defaults = array(
    		'post_id' => false,
    		'new_post' => array(),
    		'field_groups' => array(),
    		'form' => true,
    		'form_attributes' => array(
    			'id' => 'post',
    			'class' => '',
    			'action' => '',
    			'method' => 'post',
    		),
    		'return' => add_query_arg( 'updated', 'true', get_permalink() ),
    		'html_before_fields' => '',
    		'html_after_fields' => '',
    		'submit_value' => __("Update", 'acf'),
    		'updated_message' => __("Post updated", 'acf'), 
    	);
    	
Viewing 1 post (of 1 total)

The topic ‘array_merge error in API when using acf_form new_post’ is closed to new replies.