Home › Forums › Bug Reports › Taxonomies not saving for users › Reply To: Taxonomies not saving for users
I see this is marked as solved but I don’t think it is. I ran into the same problem, that user taxonomies would not save as taxonomy terms. They saved just fine as user_meta but not when “Load value based on the post’s terms and update the post’s terms on save” is checked. Two changes to the field taxonomy.php seem to take care of it. The update_value needs to consider user_ids like this:
function update_value( $value, $post_id, $field )
{
// vars
if( is_array($value) )
{
$value = array_filter($value);
}
if( $field['load_save_terms'] )
{
// Parse values
$value = apply_filters( 'acf/parse_types', $value );
if( strpos( $post_id, 'user' ) !== false ) {
$user_id = substr($post_id, 5);
wp_set_object_terms( $user_id, $value, $field['taxonomy'], false );
} else {
wp_set_object_terms( $post_id, $value, $field['taxonomy'], false );
}
}
return $value;
}
The load_value function needs to use the more general wp_get_object_terms instead of get_the_terms like this:
function load_value( $value, $post_id, $field )
{
if( $field['load_save_terms'] )
{
$value = array();
$terms = wp_get_object_terms( $post_id, $field['taxonomy'] );
if( is_array($terms) ){ foreach( $terms as $term ){
$value[] = $term->term_id;
}}
}
return $value;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.