User registration with post creation – Full Name field in post title?
-
Hi – I have this mu-plugin working nicely on forms that only create new custom posts of type ‘results’: the title and slug of the post are updated when saving the post, using a Full Name field and the time of submission.
However, when I use the same set-up on a user registration form that also creates ‘results’ posts, the Full Name value is missing in the post title, only the submission time is saved. What am I missing?
- It’s the same field name, {name-1}, in both types of forms.
- The only difference for the Full Name field on the non-registration form is that it’s auto-filled (by Display Name) as users must be logged in to use that form, however it’s also editable (in case they need to submit a family member’s results).
The plugin:
<?php /** * Plugin Name: Forminator Postdata Autofill Results Title * Description: Creates a post title from submitter name and date/time of submission, for race results, so the submitter doesn't have to invent a title. */ function mg2022_autofill_results_title( $post_id, $field, $data ){ if( get_post_type($post_id) == 'results'){ // only do this for results post type $membername = esc_attr( $_POST['name-1'] ); // common full name field for all 3 forms submitting results $submitdate = date( 'Y-m-d H:i:s', time() ); // current (submitted) date and time $newtitle = 'Result from ' . $membername . ' — ' . $submitdate; $newslug = sanitize_title($newtitle); $my_result = array( 'ID' => $post_id, 'post_title' => $newtitle, 'post_name' => $newslug, ); // Update the post into the database wp_update_post( $my_result ); } } add_action( 'forminator_post_data_field_post_saved', 'mg2022_autofill_results_title', 10, 3 );
Thanks in advance.
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘User registration with post creation – Full Name field in post title?’ is closed to new replies.