Support

Account

Home Forums General Issues Using acf_form – add post title… Reply To: Using acf_form – add post title…

  • Thanks for the reply, @junixvillacorta – so I have added this in (I did have this… but used your code now so we’re on the same page) but it still doesn’t seem to be saving the title…

    <?php $options = array(
    	'post_id' => 'new',
    	'html_before_fields' => '<input type="text" name="post_title" size="30" id="title" placeholder="Enter title here" autocomplete="off">',
    	'field_groups' => array(835),
    	'submit_value' => 'Submit your listing'
    ); ?>
    
    <div class="container_12">
    	<div class="prefix_3 grid_9">
    		<div class="submit-form-container">
    			<h2>Submit your listing</h2>
    			<?php acf_form($options); ?>
    		</div>
    	</div>
    </div>
    <div class="clear"></div>
    // Create the frontend form
    function ps_acf_save_post( $post_id ) {
        // Don't do this on the ACF post type
        if ( get_post_type( $post_id ) == 'acf' ) return;
    
        // Get the Fields
        $fields = get_field_objects( $post_id );
    
        // Prevent Infinite Looping...
        remove_action( 'acf/save_post', 'my_acf_save_post' );
    
        // Grab Post Data from the Form
        $post = array(
            'ID'           => $post_id,
            'post_type'    => 'events',
            'post_title'   => $fields['new_title']['value'],
            'post_status'  => 'draft'
        );
    
        // Continue save action
        add_action( 'acf/save_post', 'my_save_post' );
    
        // Set the Return URL in Case of 'new' Post
        $_POST['return'] = add_query_arg( 'updated', 'true', get_permalink( $post_id ) );
    }
    add_action( 'acf/save_post', 'ps_acf_save_post', 10, 1 );