How To Set Custom Post Type Title Without Supports

I’ve dabbled in this as well. For a meta box I recommend the Meta Box plugin (which I regularly contribute code to). A good tutorial on how to use it is here. For custom columns, do a search in WPSE but this should get you started. Saving the post title involves using the save_post filter. When you set up your meta box, remember the id you used for the first and last names and replace then in the code below:

add_filter( 'save_post_athlete', 'wpse88655_set_title', 10, 3 );
function wpse88655_set_title ( $post_id, $post, $update ){
    //This temporarily removes filter to prevent infinite loops
    remove_filter( 'save_post_athlete', __FUNCTION__ );

    //get first and last name meta
    $first = get_metadata( 'athelete_first_name', $post_id ); //meta for first name
    $last = get_metadata( 'athelete_last_name', $post_id );   //meta for last name

    $title = $first . ' ' . $last;

    //update title
    wp_update_post( array( 'ID'=>$post_id, 'post_title'=>$title ) );

    //redo filter
    add_filter( 'save_post_athlete', __FUNCTION__, 10, 3 );
}

Leave a Comment