Skip to content

Instantly share code, notes, and snippets.

@robbm76
Last active August 30, 2016 20:26
Show Gist options
  • Save robbm76/6da26b53f2f3751e0ac1e553f9060620 to your computer and use it in GitHub Desktop.
Save robbm76/6da26b53f2f3751e0ac1e553f9060620 to your computer and use it in GitHub Desktop.
Maps ACF text field 'last_name' to post title.
<?php
// map last name to title
function my_acf_update_value( $value, $post_id, $field ) {
global $_POST;
// vars
$new_title = get_field('last_name', $post_id) . ' ' . $value;
$new_slug = sanitize_title( $new_title );
// update post
// http://codex.wordpress.org/Function_Reference/wp_update_post
$my_post = array(
'ID' => $post_id,
'post_title' => $new_title,
'post_name' => $new_slug
);
// Update the post into the database
wp_update_post( $my_post );
}
add_filter('acf/update_value/name=last_name', 'my_acf_update_value', 10, 3);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment