Skip to content

Instantly share code, notes, and snippets.

@brycejacobson
Last active August 16, 2017 14:50
Show Gist options
  • Save brycejacobson/0f26778323315a9d6856519445fd1542 to your computer and use it in GitHub Desktop.
Save brycejacobson/0f26778323315a9d6856519445fd1542 to your computer and use it in GitHub Desktop.
Auto-populate Custom Post Type Title with ACF field.
<?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