Auto generate post title – how to include different post meta
-
I have the following snippet that allows me to auto generate the post title. I’d like to change the
$post_type
of the'post_title' => $post_type . ' Job #' . $post_id
to some other post meta like post date and post author.Thanks heaps.
function save_post_func_2134( $post_id ) { $post_type = 'post'; //Change your post_type here if ( $post_type == get_post_type ( $post_id ) ) { //Check and update for the specific $post_type $my_post = array( 'ID' => $post_id, 'post_title' => $post_type . ' Job #' . $post_id //Construct post_title ); remove_action('save_post', 'save_post_func_2134'); //Avoid the infinite loop // Update the post into the database wp_update_post( $my_post ); } } add_action( 'save_post', 'save_post_func_2134' );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Auto generate post title – how to include different post meta’ is closed to new replies.