Answers for "custom field post value replace wordpress post title"

0

custom field post value replace wordpress post title

add_action( 'acf/save_post', 'biwp_set_title_from_first_last_name', 20 );

function biwp_set_title_from_first_last_name( $post_id ) {
    $post_type = get_post_type( $post_id );

    if ( 'contributor' == $post_type ) {
        $first_name = get_field( 'biwp_first_name', $post_id );
        $last_name = get_field( 'biwp_last_name', $post_id );

        $title = $first_name . ' ' . $last_name; 

        $data = array(
            'ID'         => $post_id,
            'post_title' => $title,
            'post_name'  => sanitize_title( $title ),
        );

        wp_update_post( $data );
    }
}
Posted by: Guest on July-02-2021

Code answers related to "custom field post value replace wordpress post title"

Browse Popular Code Answers by Language