Hi
I want to set proper title for automatically created by users through post form. If it's possible I'd like to use some field info from the post form.
I checked this topic but I couldn't handle anyway.
https://toolset.com/forums/topic/saving-user-first-name-last-name-as-post-title-post-date-time/
I tried to copy code on the top this page and add to my site specific plugin but it isn't working, no signal to chase.
Can you help me?
Kutay
Hello Kutay and thank you for contacting the Toolset support.
Can you share the code that you are using? Or allow me temporary access to your website to check it closely?
Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
Thank you for the credentials.
I believe you are talking about this custom code, right? Please let me know if you are talking about another code?
function md_checkout_title( $post_id ) {
if( 'material-check-out' == get_post_type($post_id) ) {
remove_action( 'save_post', 'md_checkout_title' );
$date = date( 'Y-m-d H:i:s', time() );
$author_id = get_post_field( 'post_author', $post_id );
$first_name = get_the_author_meta( 'first_name', $author_id );
$updated_data = array(
'ID' => $post_id,
'post_title' => $first_name . $date
);
wp_update_post( $updated_data );
add_action( 'save_post', 'md_checkout_title' );
} else {
return;
}
}
add_action( 'save_post', 'md_checkout_title' );
If this is the case, you will need to update the code to suit your use case.
- Change "material-check-out" on line 2 with your custom post type.
- Change lines 4-11 to suits your logic to build title.
How would you like to build your automatic title?
Thanks a lot. This works but I might have further related questions. I don't want to mess the support center, that's why would you mind If I ask that you not to close this ticket for a while.
Of course! I am setting this ticket as waiting for your response. It should be kept open for 3 weeks.
Feel free to open a new ticket for any other question or issue.