//code starts, code is in function.php:
function acf_title( $value, $post_id, $field ) {
$post_object = get_field(‘select_user’);
$get_firstname = get_field(‘first_name’, $post_object->ID);
$get_lastname = get_field(‘last_name’, $post_object->ID);
$new_title = $ get_firstname . ‘ ‘ . $ get_lastname;
$slug = sanitize_title( $new_title);
// update post
wp_update_post( array(
‘ID’ => $post_id,
‘post_title’ => $new_title,
‘post_name’ => $slug
) );
wp_update_post( $postdata );
$value = preg_replace(‘/\s+/’, ”, $value);
return $value;
}
add_filter(‘acf/update_value/name=select_user, ‘acf_title’, 10, 3);
//code ends
The above code changes the post title, and it works fine enough. But what is the ’proper’ way to update post category from $post_object using the above ’wp_update_post’ -array?
$post_object gets data from custom post type ’peoples’ and that post type has the following ACF fields:
firstname, text
lastname, text
birthday, date picker
group, taxonomy
*additional information from taxonomy field ‘group’ settings:
Taxonomy: category
Field Type: Select
Allow null: no
Load & Save Terms to Post: checked
Return Value: checked Term ID
Conditional Logic: no
I can get the he category name and id to the post from the $post_object and save it using $variable in the post content itself, but i haven’t been able to change the post category ’automatically’ during the save process. Is this possible?