Last active
August 16, 2017 14:50
-
-
Save brycejacobson/0f26778323315a9d6856519445fd1542 to your computer and use it in GitHub Desktop.
Auto-populate Custom Post Type Title with ACF field.
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
<?php | |
// Auto-populate Staff post title with ACF name field. | |
function efd_staff_post_title_updater($post_id) | |
{ | |
$my_post = array(); | |
$my_post['ID'] = $post_id; | |
if (get_post_type() == 'staff') { | |
$my_post['post_title'] = get_field('name'); // Update Title | |
$my_post['post_name'] = get_field('name'); // Update Slug | |
} | |
// Update the post into the database | |
wp_update_post($my_post); | |
} | |
// run after ACF saves the $_POST['fields'] data | |
add_action('acf/save_post', 'efd_staff_post_title_updater', 20); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment