Support

Account

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

Solved

'A title, maybe a $_POST variable' how to?

  • Hello, friends!

    Please tell me how to transfer the value of two or three fields from the form on the front-end to the ‘post_title’?
    In “Group1” I have 3 fields: Title (title), Field1 (field1), Field2 (field2)

    I would like to make such a title, for example –
    ‘post_title’ => Title + Field1 + Field2

    Thank you

  • What kind of fields are they? Text fields?
    Where are the fields located in the dashboard?

    <?php
      $title = get_field('title');
      $field1 = get_field('field1');
      $field2 = get_field('field2');
    ?>
    <h1 class="post-title"><?php echo $title $field1 $field2; ?></h1>
  • 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' );
  • Hi @Dmitry Averin

    To concatinate strings, you do so like this:
    $string = 'foo' . 'bar';

    So ACF $_POST data would look like:
    'post_title' => $_POST['acf']['field_5481ab2cdda13'] . ' ' . $_POST['acf']['field_5481ab2cdda14'],

    Hope that helps

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

You must be logged in to reply to this topic.