Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dgoze/1331afa889b1d2e71b399380e4205b33 to your computer and use it in GitHub Desktop.
Save dgoze/1331afa889b1d2e71b399380e4205b33 to your computer and use it in GitHub Desktop.
Using Advanced Custom Fields to create your Post Title
<?php
/** Create Title and Slug */
function acf_title( $value, $post_id, $field ) {
if ( get_post_type( $post_id ) === 'staff' ) {
$new_title = get_field( 'first_name', $post_id ) . ' ' . $value;
$new_slug = sanitize_title( $new_title );
wp_update_post(
array(
'ID' => $post_id,
'post_title' => $new_title,
'post_name' => $new_slug,
)
);
}
return $value;
}
add_filter( 'acf/update_value/name=last_name', 'acf_title', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment