Support

Account

Forum Replies Created

  • Hello,

    For me, it works fine, did you change the names of the fields ?
    If the screen is blank, you should have a php error, with an error message. Do you “display_errors=1” in your php.ini ? If you dont have access to php.ini, i think you can put that instruction in .htaccess

    Good luck

  • And now ? it is working perfectly !

    
    <?php
    /**
     * Template Name: Page Creation Vigneron3.0 2
     */
    
    ?>
    <?php
    // fonction ACF --------------------------------------------
    // with this i dont have to think to put acf_form_head whereever I need it, it is always there
    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'   => $_POST['fields']['field_5640802e05f78'],
     		'post_content'   => $_POST['fields']['field_5640802e05f79'],
    		'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' );
    
    function my_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 );
    
        // Grab Post Data from the Form
        $post = array(
    		'ID'			=> $post_id,
      		'post_title'   	=> $fields['titre']['value'],
     		'post_content'  => $fields['contenu']['value'],
       );
        // Update the Post
    	wp_update_post( $post,true );
    }
    add_action( 'acf/save_post', 'my_acf_save_post', 10, 1 );
    ?>
    
    <?php get_header(); ?>
    
    	<div id="primary" class="content-area">
    		<?php 
    			$args = array(
    				'post_id'    => 'new',
    				'post_title' => false,
    				'post_content' => false,
    				'field_groups' => array( 5015 ),
    				'submit_value' => "Valider cette nouvelle action"
    			);
    			acf_form( $args ); 
    		?>
    
    	</div><!-- #primary -->
    
    <?php get_footer(); ?>
    
  • 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(); ?>
    
  • I am looking for the same, a research on a logical in a repeated … i tried hard but …
    Anyone ?

  • Easy !

    function my_acf_load_value( $value, $post_id, $field )
    {
        return $_GET['id'];
    }
    add_filter('acf/load_value/key=field_547ccecd7b091', 'my_acf_load_value', 10, 3);

    I dont know why 10 and 3, it is in the documentation.

  • No it does not change anything for me.

    Anyway, I do not understand one thing, acf/pre_save_post is fired when the post is saved in the data base no ? when I try to create new record, acf/pre_save_post is not used befor acf_form() is used no ?

    If I look in the sources of my page when acf_form() is called, I see a field names someting like field_5483b32a04842 is used. I am wondering : how could I pre load a value in that field, then the user could validate it without retyping it …

    No help ?

  • 5 minutes later:

    If i use update_sub_field instead, it seems to work !

  • Hello,
    I have the same error, with a simple text field !
    if I // update_field(‘slug_de_larticle’,$cSlug); then it works.
    BTW i use also a repeater field, but the text field is not a part of it.
    Thanks for your help.

  • Hi Elliot,
    is this still in the todo ? it would be great : “Disable fields based on user permission level”
    Thanks for all …

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