Skip to content

Instantly share code, notes, and snippets.

@solid-pixel
Created March 20, 2017 12:20
Show Gist options
  • Save solid-pixel/790144f61f4c0bc247a35907bf139cdb to your computer and use it in GitHub Desktop.
Save solid-pixel/790144f61f4c0bc247a35907bf139cdb to your computer and use it in GitHub Desktop.
Populate Post Title with ACF field value
//Auto add and update Title field:
function my_post_title_updater( $post_id ) {
$my_post = array();
$my_post['ID'] = $post_id;
// custom post type
if ( get_post_type() == 'case_study' ) {
$my_post['post_title'] = get_field('case_study_title');
}
// Update the post into the database
wp_update_post( $my_post );
}
// run after ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'my_post_title_updater', 20);
//END Auto add and update Title field:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment