post对象作为save_post
action (do_action ( \'save_post\', int $post_ID, WP_Post $post, bool $update )
。您可以使用此post对象从中获取发布日期和作者。
您可以尝试以下操作:(注意:代码未经测试)
add_action( \'save_post\', \'wpse_214927_alter_title\', 10, 2 );
function wpse_214927_alter_title ( $post_id, $post_object )
{
// Target only specific post type
if ( \'my_specific_post_type\' !== $post_object->post_type
&& \'my_other_specific_post_type\' !== $post_object->post_type
)
return;
// Remove the current action
remove_action( current_filter(), __FUNCTION__ );
$post_date = $post_object->post_date;
$format_date = DateTime::createFromFormat( \'Y-m-d H:i:s\', $post_date );
$date_formatted = $format_date->format( \'Y-m-d\' ); // Set correct to display here
$post_author = $post_object->post_author;
$author_name = get_the_author_meta( \'display_name\', $post_author ); // Adjust as needed
$my_post = [
\'ID\' => $post_id,
\'post_title\' => $author_name . \' Job \' . $date_formatted // Change as needed
];
wp_update_post( $my_post );
}
重要的是,您应该在需要的地方添加验证和卫生