Wednesday, August 10, 2022
HomeWordPress Developmentphp - Generate the submit title from ACF fields

php – Generate the submit title from ACF fields


I need to generate submit title from first identify and final identify that are two fields. The posts are generated in WS Kind and saved with no title.

I attempted this code nevertheless it doesn’t appear to work.
Any ideas?!

    perform set_post_title_from_acf($post_id){

        $my_post = array();
        $my_post['ID'] = $post_id

        if (get_post_type($post_id) == 'employees'){

            $first_name = get_field('first_name',$post_id);
            $last_name = get_field('last_name',$post_id);

            $my_title = $first_name . ' ' . $last_name;
            $my_post['post_title'] = $my_title;
            $my_slug = sanitize_title($my_title);
            $my_post['post_name'] = $my_slug;
            wp_update_post($my_post);

        }

    }
    add_action('save_post','set_post_title_from_acf',20);

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments