单击“发布”时,在帖子标题中自动添加帖子的作者姓名。
- function fun_update_post_title( $post_id, $post, $update ) {
- if ( wp_is_post_revision( $post_id ) )
- return;
- $post_author_name = get_the_author_meta( "display_name",$post->post_author );
- $post_author_name2 = '撰写';
- $post_title = $post->post_title."-".$post_author_name."-".$post_author_name2;
- $my_post = array(
- 'ID' => $post_id,
- 'post_title' => $post_title
- );
- remove_action('save_post', 'fun_update_post_title');
- wp_update_post( $my_post );
- add_action('save_post', 'fun_update_post_title');
- }
- add_action( 'save_post', 'fun_update_post_title', 10, 3 );