Support

Account

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

  • All was working sooooo swimmingly! I was thrilled! Until…

    The client has asked for several related custom post types. They require different types of titles. I thought I could just duplicate the functions used above making minor modifications so they were unique, but it breaks the whole thing. There’s gotta be some sort of syntax I’m missing here to make it happen.

    Here’s what I’ve got:

    Functions.php

    //Auto add and update Title field for English/Yes form:
    function vbs_post_title_updater( $post_id ) {
        
        // 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 . ' - ' . $new_title_date->format('M j, Y');
        
        $new_slug = sanitize_title( $new_title );
    
        // create the update data holder
    	$vbs_ey_post = array();
    	$vbs_ey_post['ID'] = $post_id;
    	$vbs_ey_post['post_title'] = $new_title;
    	$vbs_ey_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_ey_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);
    
    //Auto add and update Title field for English/No form:
    function vbs_post_title_updater2( $post_id2 ) {
        
        // get the church name
        $new_title_church_name2 = get_field('church_name2', $post_id2);
    
        // set the title
        $new_title2 = $new_title_church_name2;
        
        $new_slug2 = sanitize_title( $new_title2 );
    
        // create the update data holder
    	$vbs_en_post = array();
    	$vbs_en_post['ID'] = $post_id2;
    	$vbs_en_post['post_title'] = $new_title2;
    	$vbs_en_post['post_name'] = wp_strip_all_tags($new_slug2);
    
        //Unhook function to prevent infinite looping
    	remove_action('acf/save_post', 'vbs_post_title_updater2', 20);
    
    	// Update the post into the database
    	wp_update_post( $vbs_ey_post );
    
    	//Rehook function to prevent infitnite looping
    	add_filter('acf/save_post', 'vbs_post_title_updater2', 20);
    
    }
    // run after ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'vbs_post_title_updater2', 20);

    Page – English/Yes

    $vbs_ey_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_ey_post ); ?>

    Page – English/No

    $vbs_en_post = array(
    		'post_id'		=> 'new_post',
    		'post_title'	=> wp_strip_all_tags($new_title2),
    		'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!',
    		'post_title'    => wp_strip_all_tags($new_slug2),
    	);
    	
    	acf_form( $vbs_en_post ); ?>

    As long as I only have the first function running, the one form works great. It saves the title, redirects, all of it. If I add the one for English/No, Neither one of them redirect or save titles properly.

    Note: I have reflushed permalinks several times through this process.

    It just occurred to me that it might be helpful to see the custom post type functions as well, since *maybe* something about them is part of the issue?

    Custom Post Types

    add_action('init', 'ey');
    function ey()
    {
    	$labels = array(
    		'name_admin_bar' => 'VBS Submissions',
    		'all_items' => 'All English/Yes Submissions',
    		'name' => 'English/Yes Submission',
    		'singular_name' => 'English/Yes Submission',
    		'menu_name' => 'VBS Submissions',
    		'add_new' => false,
    		'add_new_item' => 'Add New English/Yes Submission',
    		'edit' => 'Edit',
    		'edit_item' => 'Edit English/Yes Submission',
    		'new_item' => 'New English/Yes Submission',
    		'view' => 'View English/Yes Submission',
    		'view_item' => 'View English/Yes Submission',
    		'search_items' => 'Search English/Yes Submissions',
    		'not_found' => 'No English/Yes Submission Found',
    		'not_found_in_trash' => 'No English/Yes Submission Found in Trash',
    		'parent' => 'Parent English/Yes Submission',
    	);
    		
    	$args = array(
    		'label' => 'VBS Submissions',
    		'labels' => $labels,
    		'description' => '',
    		'public' => true,
    		'show_ui' => true,
    		'show_in_menu' => true,
    		'capability_type' => 'post',
    		'hierarchical' => true,
    		'rewrite' => array(
    			'slug' => ''
    		),
    		'menu_icon' => 'dashicons-smiley',
    		'query_var' => true,
    		'exclude_from_search' => false,
    		'supports' => array( 'author', 'title' ),
    		'menu_position' => 5,
    		'add_new' => false,
    	);
    		
    register_post_type( 'ey' , $args );
    }
    
    add_action('init', 'en');
    function en()
    {
    	$labels = array(
    		'all_items' => 'All English/No Submissions',
    		'name' => 'English/No Submission',
    		'singular_name' => 'English/No Submission',
    		'menu_name' => 'English/No Submission',
    		'add_new' => 'VBS English/No Submission',
    		'add_new_item' => 'Add New English/No Submission',
    		'edit' => 'Edit',
    		'edit_item' => 'Edit English/No Submission',
    		'new_item' => 'New English/No Submission',
    		'view' => 'View English/No Submission',
    		'view_item' => 'View English/No Submission',
    		'search_items' => 'Search English/No Submissions',
    		'not_found' => 'No English/No Submission Found',
    		'not_found_in_trash' => 'No English/No Submission Found in Trash',
    		'parent' => 'Parent English/No Submission',
    	);
    		
    	$args = array(
    		'label' => 'English/No Submissions',
    		'labels' => $labels,
    		'description' => '',
    		'public' => true,
    		'show_ui' => true,
    		'show_in_menu' => true,
    		'capability_type' => 'post',
    		'hierarchical' => true,
    		'rewrite' => array(
    			'slug' => ''
    		),
    		'query_var' => true,
    		'exclude_from_search' => false,
    		'supports' => array( 'author', 'title' ),
    		'show_in_menu'  =>	'edit.php?post_type=ey',
    		'menu_position' => 2
    	);
    		
    register_post_type( 'en' , $args );
    }
    
    add_action('init', 'sy');
    function sy()
    {
    	$labels = array(
    		'all_items' => 'All Spanish/Yes Submissions',
    		'name' => 'Spanish/Yes Submission',
    		'singular_name' => 'Spanish/Yes Submission',
    		'menu_name' => 'Spanish/Yes Submission',
    		'add_new' => 'Spanish/Yes Submission',
    		'add_new_item' => 'Add New Spanish/Yes Submission',
    		'edit' => 'Edit',
    		'edit_item' => 'Edit Spanish/Yes Submission',
    		'new_item' => 'New Spanish/Yes Submission',
    		'view' => 'View Spanish/Yes Submission',
    		'view_item' => 'View Spanish/Yes Submission',
    		'search_items' => 'Search Spanish/Yes Submissions',
    		'not_found' => 'No Spanish/Yes Submission Found',
    		'not_found_in_trash' => 'No Spanish/Yes Submission Found in Trash',
    		'parent' => 'Parent Spanish/Yes Submission',
    	);
    		
    	$args = array(
    		'label' => 'Spanish/Yes Submissions',
    		'labels' => $labels,
    		'description' => '',
    		'public' => true,
    		'show_ui' => true,
    		'show_in_menu' => true,
    		'capability_type' => 'post',
    		'hierarchical' => true,
    		'rewrite' => array(
    			'slug' => ''
    		),
    		'query_var' => true,
    		'exclude_from_search' => false,
    		'supports' => array( 'author', 'title' ),
    		'show_in_menu'  =>	'edit.php?post_type=ey',
    		'menu_position' => 2
    	);
    		
    register_post_type( 'sy' , $args );
    }
    
    add_action('init', 'sn');
    function sn()
    {
    	$labels = array(
    		'all_items' => 'All Spanish/No Submissions',
    		'name' => 'Spanish/No Submission',
    		'singular_name' => 'Spanish/No Submission',
    		'menu_name' => 'Spanish/No Submission',
    		'add_new' => 'Spanish/No Submission',
    		'add_new_item' => 'Add New Spanish/No Submission',
    		'edit' => 'Edit',
    		'edit_item' => 'Edit Spanish/No Submission',
    		'new_item' => 'New Spanish/No Submission',
    		'view' => 'View Spanish/No Submission',
    		'view_item' => 'View Spanish/No Submission',
    		'search_items' => 'Search Spanish/No Submissions',
    		'not_found' => 'No Spanish/No Submission Found',
    		'not_found_in_trash' => 'No Spanish/No Submission Found in Trash',
    		'parent' => 'Parent Spanish/No Submission',
    	);
    		
    	$args = array(
    		'label' => 'Spanish/No Submissions',
    		'labels' => $labels,
    		'description' => '',
    		'public' => true,
    		'show_ui' => true,
    		'show_in_menu' => true,
    		'capability_type' => 'post',
    		'hierarchical' => true,
    		'rewrite' => array(
    			'slug' => ''
    		),
    		'query_var' => true,
    		'exclude_from_search' => false,
    		'supports' => array( 'author', 'title' ),
    		'show_in_menu'  =>	'edit.php?post_type=ey',
    		'menu_position' => 2
    	);
    		
    register_post_type( 'sn' , $args );
    }
    
    add_action( 'init', 'create_vbs_tax' );
    
    function create_vbs_tax() {
    	register_taxonomy(
    		'conferences',
    		'ey',
    		array(
    			'label' => __( 'Conferences' ),
    			'rewrite' => array( 'slug' => 'conferences' ),
    			'hierarchical' => true,
    			'menu_position' => 5
    		)
    	);
    }

    Any chance “‘show_in_menu’ => ‘edit.php?post_type=ey'” could be part of the issue?