Support

Account

Forum Replies Created

  • OK. I see the problem. Unless WP were to update the term_relationships table so it could distinguish object_ids as belonging to a user or a post, the potential for conflict is unavoidable.

    My main goal is to run taxonomy queries for a user. It would work about as well for me to run meta queries for a user except that ACF stores the taxonomy terms in a serialized array in the user_meta table. I don’t know of a reliable way to run a meta query that looks for a value in a serialized array. If ACF stored taxonomy term ids each as a separate user_meta fields, then I could effectively run a user meta query. I realize that would be a big shift for ACF and I don’t expect you to take it on.

    I’ll likely solve this by creating my own user-taxonomy field. Since I know in my particular instance I won’t have term taxonomies shared between posts and users, I’ll probably store the taxonomy terms as such but I may explore storing them as separate meta fields instead. I very much appreciate that ACF is built with enough flexibility to make it straightforward for me to create my own field for this.

  • 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;
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)