Support

Account

Home Forums Front-end Issues Creation and edition of a post Reply To: Creation and edition of a post

  • Ok, now, it is better, but not ok yet. In that case, I create a new record, and then I can edit it, at least the variables included in the acf group. But if I type something in the title field or the content field, I do net see that something in the record !

    <?php
    /**
     * Template Name: Page Creation Vigneron3.0 2
     */
    
    ?>
    <?php
    // fonction ACF --------------------------------------------
    // add_action('wp_head','acf_form_head');
    
    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'  => 'Ici, le nom du Domaine, Vignoble ...' ,
            'post_type'  => 'page' ,
    		'page_template'  => 'page_vigneron30.php',		
        );  
    
       // insert the post
       $post_id = wp_insert_post( $post );
    
       $_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' );
    
    // ---------------------------------------------------------------------------------
    
    ?>
    
    <?php acf_form_head(); ?>
    <?php get_header(); ?>
    
    	<div id="primary" class="content-area">
    		<div id="content" class="site-content" role="main">
    		<?php 
    			$args = array(
    				'post_id'    => 'new',
    				'post_title' => true,
    				'post_content' => true,
    				'field_groups' => array( 5015 ),
    				'submit_value' => "Valider cette nouvelle action"
    			);
    			acf_form( $args ); 
    		?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php get_footer(); ?>