Support

Account

Home Forums Backend Issues (wp-admin) How to populate Title from a different field

Helping

How to populate Title from a different field

  • I created a custom post type where one of the fields is a Select dropdown. I need the title of a post to be populated by whatever has been selected in this dropdown for that post. Is there any way to do this?

  • //add title and alias when a person is created
    function my_acf_update_titlevalue( $value, $post_id, $field ) {
    global $post;
    	// vars (title comes from person_name field that is looked for at the filter, after that the alias is generated)	
    	$new_title = $value;
    	$new_slug = sanitize_title( $new_title );
    	// update post with the "new" title and alias (because we may hide them at our custom post)
    	$my_post = array('ID'=> $post_id,'post_title' => $new_title,'post_name' => $new_slug );
    wp_update_post( $my_post );
    return $value;
    }
    add_filter('acf/update_value/name=person_name', 'my_acf_update_titlevalue', 10, 3);

    try something like above at your plugin: change person_name to your acf field
    hope that help and work for you

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to populate Title from a different field’ is closed to new replies.