Support

Account

Home Forums General Issues Frontend Form not populating right in backend Reply To: Frontend Form not populating right in backend

  • Functions.php

    //Auto add and update Title field for English/Yes & English/No forms:
    function vbs_post_title_updater( $post_id ) {
        
        // list the post type you want to modify
        $post_types = array('ey', 'en');
        
        // get the current post type
        $current_post_type = get_post_type($post_id);
        
        // if current post type is not in the list, don't do anything
        if( !in_array($current_post_type, $post_types) ){
            return;
        }
        
        // Set the title for 'ey' post type
        if( $current_post_type == 'ey' ) {
            
            // get the church name
            $new_title_church_name = get_field('church_name', $post_id);
    
            // get the selected date and the current date
            $new_title_date = get_field('start_date', $post_id);
            $new_title_date = new DateTime($new_title_date);
            
            // set the title
            $new_title = $new_title_church_name . ' Adventist Church - ' . $new_title_date->format('M j, Y');
        
        // set the title for 'en' post type
        } elseif ( $current_post_type == 'en' ) {
            
            // get the church name and set it directly to the post title
            $new_title = get_field('church_name2', $post_id) . ' Adventist Church';
        }
        
        $new_slug = sanitize_title( $new_title );
    
        // create the update data holder
    	$vbs_post = array();
    	$vbs_post['ID'] = $post_id;
    	$vbs_post['post_title'] = $new_title;
    	$vbs_post['post_name'] = wp_strip_all_tags($new_slug);
    
        //Unhook function to prevent infitnite looping
    	remove_action('acf/save_post', 'vbs_post_title_updater', 20);
    
    	// Update the post into the database
    	wp_update_post( $vbs_post );
    
    	//Rehook function to prevent infitnite looping
    	add_filter('acf/save_post', 'vbs_post_title_updater', 20);
    
    }
    // run after ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'vbs_post_title_updater', 20);

    EY form page

    $vbs_post = array(
    		'post_id'		=> 'new_post',
    		'post_title'	=> wp_strip_all_tags($new_title),
    		'post_content'	=> false,
    		'form' => true,
    		'new_post'		=> array(
    			'post_type'		=> 'ey',
    			'post_status'	=> 'publish'
    		),
    		'field_groups'       => array(2793),
    		'return'             => '%post_url%',
    		'submit_value'       => 'Submit VBS Event',
    		'updated_message'    => 'Saved!'
    	);
    	
    	acf_form( $vbs_post );

    EN form page

    $vbs_post = array(
    		'post_id'		=> 'new_post',
    		'post_title'	=> wp_strip_all_tags($new_title),
    		'post_content'	=> false,
    		'form' => true,
    		'new_post'		=> array(
    			'post_type'		=> 'en',
    			'post_status'	=> 'publish'
    		),
    		'field_groups'       => array(3052),
    		'return'             => '%post_url%',
    		'submit_value'       => 'Submit',
    		'updated_message'    => 'Saved!'
    	);
    	
    	acf_form( $vbs_post );

    I also just now tried without the “‘post_title’ => wp_strip_all_tags($new_title),” in the array for en, but it didn’t solve it.

    I don’t *think* I still have the errant acf/save_post you mention. But I concede that I simply may not be seeing it.