Created
March 20, 2017 12:20
-
-
Save solid-pixel/790144f61f4c0bc247a35907bf139cdb to your computer and use it in GitHub Desktop.
Populate Post Title with ACF field value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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