Support

Account

Home Forums ACF PRO 'A title, maybe a $_POST variable' how to? Reply To: 'A title, maybe a $_POST variable' how to?

  • Text fields from front end form, Ben.
    How do I combine multiple fields in the title? What is the syntax for concatenate?
    ‘post_title’ => $_POST[‘acf’][‘field_5481ab2cdda13’] [‘field_54814faa2f090’], //NOT work
    For example of title- NAME+CITY+DATE –> DMITRY::MOSCOW::22.11.2014 (:: – separator).

    Help me, plz

    My front-end form –

    <?php 
    /**
     * Template Name: Page with ACF form
     */
    acf_form_head();
    get_header(); 
    the_post(); 
    ?>
    	<div id="primary">
    		<div id="content" role="main">
    			<?php 
    			$args = array(
    				'post_id' => 'new',
    				'field_groups' => array( 5 ),
    				'updated_message'	=> 'Up the post!'
    			);
    			acf_form( $args ); 
    			?>
    
     ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Plugin –

     
    /**
    * ACF Frontend Form
    */
    
    function my_pre_save_post( $post_id )
    {
        // check if this is to be a new post
        if( $post_id != 'new' )
        {
            return $post_id;
        }
    
        // Create a new post
        $post = array(
            'post_status'  => 'publish' ,
            'post_title'  => $_POST['acf']['field_5481ab2cdda13'],
            'post_type'  => 'testimonials' ,
            'post_category'=>array(4),
        );  
    
        // insert the post
        $post_id = wp_insert_post( $post ); 
    
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
    
        // return the new ID
        return $post_id;
    }
    
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );