Last active
August 30, 2016 20:26
-
-
Save robbm76/6da26b53f2f3751e0ac1e553f9060620 to your computer and use it in GitHub Desktop.
Maps ACF text field 'last_name' to post title.
This file contains 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 | |
// set image upload as featured image | |
function acf_set_featured_image( $value, $post_id, $field ){ | |
if($value != ''){ | |
//Add the value which is the image ID to the _thumbnail_id meta data for the current post | |
add_post_meta($post_id, '_thumbnail_id', $value); | |
} | |
return $value; | |
} | |
// acf/update_value/name={$field_name} - filter for a specific field based on it's name | |
add_filter('acf/update_value/name=photo', 'acf_set_featured_image', 10, 3); |
This file contains 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 | |
// 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