Support

Account

Forum Replies Created

  • not sure which errors you’re getting but in your pre_save_post function make sure your category value is within an array:

    'post_category'=> array($_POST['fields']['field_53b4955981c40']),

    and also if you’re editing the post you need to refer to the post ID:

    'ID' => $post_id,

  • apostolix’s code is correct you just need to make sure you point out to the correct form id, in apostolix’s case was acf_95 but yours will be different for sure.

    Also make sure nothing else on the page is using that same id (this was my problem)

  • check if you have ANY blank spaces before your code in template_form.php and remove them. Also worth checking all your other files index.php, header.php for blank spaces before (and after) code. It’s a common cause for this error.

    If it doesn’t, try putting <?php acf_form_head(); ?> in your header.php instead (before any code and without any spaces before as I mentioned above)

    Hope this helps.

  • sorted now, just needed to read what the errors had to say… 🙂

  • Ok so I’ve managed to isolate the problem to a categories field in my fron end form (the user gets to choose which category the post should go into). If the user leaves it as ‘none'(null) there are no errors but if a category is chosen the submitting errors above are displayed. I can’t test this for editing the post because I’m also having this issue: http://support.advancedcustomfields.com/forums/topic/when-selecting-taxonomy-acf-fields-disappear/#post-15118

    I’ve added a bit more info on the code I’m using below as I’m probably doing something wrong…

    Would greatly appreciate any help with this

    my form for submiting:

    <?php 
        $args = array(
            'post_id' => 'new',
    		'field_groups' => array( 'acf_add_post' ),			
    		'submit_value' => 'Add Post',
    		'return' => add_query_arg( 'updated', 'true', get_site_url()),// return url
    		);     
        acf_form( $args ); 
    ?>

    my form for editing:

    <?php
    	$args = array(
    		'post_id' => $post->ID,
    		'field_groups' => array( 'acf_add_post' ), 			
    		'submit_value' => 'Edit Post',
    		'return' => add_query_arg( 'updated', 'true', get_permalink() ),// return url
    	);     
        acf_form( $args ); 
    ?>

    my pre_save_post function:

    function my_pre_save_post( $post_id ){
        
    	// Create the post
    	$post = array(
    		'post_status'  => 'publish' ,
    		'post_title'  =>  $_POST['fields']['field_53701ca623c65'],				
    		'post_content' => $_POST['fields']['field_53701c4623c64'],				
    		'post_category'	=> $_POST['fields']['field_53b4955981c40'],
    		'post_type'  => 'post'
        ); 
    	
    	if( $post_id != 'new' )	{	// check if this is to be an edit instead of a new post	
        	
            $post_id = wp_update_post( $post ); // update the post 		
        }
    	else {  
        
    		$post_id = wp_insert_post( $post ); // insert the post
    	}
      
        return $post_id;						// return the post (new or edited)
    }
      
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );

    my exported php:

    include_once('advanced-custom-fields/acf.php');
    
    //Register ACF fields
    if(function_exists("register_field_group"))
    {
    	register_field_group(array (
    		'id' => 'acf_add_post',
    		'title' => 'Add_post',
    		'fields' => array (
    			array (
    				'key' => 'field_53701ca623c65',
    				'label' => 'Title',
    				'name' => 'title',
    				'type' => 'text',
    				'required' => 1,
    				'default_value' => '',
    				'placeholder' => 'Title',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => 50,
    			),
    			array (
    				'key' => 'field_537e8061c8a97',
    				'label' => 'Description',
    				'name' => 'description',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => 'what\'s your post about?',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => 100,
    			),
    			array (
    				'key' => 'field_53b4955981c40',
    				'label' => 'Category',
    				'name' => 'category',
    				'type' => 'taxonomy',
    				'taxonomy' => 'category',
    				'field_type' => 'select',
    				'allow_null' => 1,
    				'load_save_terms' => 1,
    				'return_format' => 'object',
    				'multiple' => 0,
    			),
    ...
  • Hi,

    I have a very similar issue. Did you manage to solve this?

    My theme/form works fine on my local wamp instalation but when I install it on a live wp site it displays a very similar error to yours whenever I try to post.

    Have you managed to fix this since your last reply? If you or anyone could share any light into this I would appreciate it.

    Thanks

  • Thanks, I was having the same issue and this also sorted it for me.

    EDIT: I had asked a question but it happens it was a problem with the live wp installation and not the plugin, thanks!

  • Sorry, please disregard my previous post.

    I’ve been doing some reading on adding ACF to my theme and what I’m asking on my previous post sounds quite silly now.

    Thanks for the amazing plugin!

  • Hi,

    I have a very similar problem. I’m currently using:

    'post_content' => $_POST['fields']['field_53701c4623c64'],

    to pass the value of a custom field I called ‘content’.

    Is there any way to call the field key from the database using the field name? Or to set the field name as the input tag name in the DOM instead of the field key? As @funack mentioned using the field key requires hardcoding when using different environments.

    Also, in case this is not possible, if I include ACF within my WP Theme will any custom field keys I create be kept? (so other users can plug and play?) I don’t think it will be because it gets the values from the database or is this not the case?

    I would appreciate any help.

    Thanks
    Carlos

  • Hi apostolix,

    Thanks for sharing your solution.

    I have the same problem but with all user types and your solution didn’t work for me even though I’ve changed your code to match my fields and the location

    I would appreciate it if you could elaborate a bit more on this issue so I can try to fix it.

    Many thanks!

  • Hey Marcella, thank you very much for this!

    Your solution worked for me too and ACF probably needs to be fixed according to your code.

    Hopefully an admin/author will see this post and flag it.

    Thanks again and best of luck with your website! x

  • Hi Marcella,

    I’m having the same problem with a repeated form (one instance for adding posts another for editing)

    The date picker on the 2nd form is not working. From having a look at the example on your website you seem to have fixed it.

    I would really appreciate it if you could explain how you fixed it.

    Thanks

    Carlos

  • having the same problem here.. Has anyone figured out a solution yet?

    Any feedback would be appreciated, thanks!

    Error: “Warning: array_merge() [function.array-merge]: Argument #1 is not an array in …wp-content/plugins/advanced-custom-fields/core/api.php on line 1185″

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