Support

Account

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

  • Hi James,
    Thanks again for your help here. Client did upgrade to Pro (solving issue #3) and I believe I’ve gotten the appropriate codes modified now so I’m not having issues #1 anymore. YAY!

    I’m still having trouble with item #2 however. I get the first part of the title working properly, but the date it’s adding is today’s date, not the date entered in the start_date date picker field.

    Here’s what I have for that area. Perhaps you’ll see what I’m doing wrong:

    function vbsform_update_title( $value, $post_id, $field ) {
    	
    	$new_title_church_name = get_field( 'church_name', $post_id) . ' ' . $value;
    	
    	$new_title_date = get_field('start_date', $post_id);
    	
    	// make date object
    	$new_title_date = new DateTime($new_title_date);
    	
    	$new_title = $new_title_church_name . '-' . $new_title_date->format('M j, Y');
    	
    	$new_slug = sanitize_title( $new_title );
    	
    	// update post
    	$vbs_postdata = array(
    		'ID'          => $post_id,
    		'post_title'  => $new_title,
    		'post_name'   => $new_slug,
    	);	
    	
    	if ( ! wp_is_post_revision( $post_id ) ){
    	
    		// unhook this function so it doesn't loop infinitely
    		remove_action('save_post', 'vbs_update_title');
    	
    		// update the post, which calls save_post again
    		wp_update_post( $vbs_postdata );
    
    		// re-hook this function
    		add_action('save_post', 'vbs_update_title');
    	}	
    	
    	return $value;
    }

    Still working on items #4 & #5. Hopefully I’ll get those figured out in the meantime 🙂