Problem: I would like to use the post author's name with post date and time to automatically set a new post title.
Solution: Use the save_post hook provided by WordPress to automate the post title. Get author information using get_the_author_meta, concatenate the title string, and use wp_update_post to update the post title. Example 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' );
Relevant Documentation:
https://developer.wordpress.org/reference/functions/wp_update_post/
https://developer.wordpress.org/reference/hooks/save_post/
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Our next available supporter will start replying to tickets in about 2.13 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 22 replies, has 3 voices.
Last updated by 4 years, 10 months ago.
Assisted by: Christian Cox.