How to sort out user based on custom taxonomy term?

Support MB User Meta How to sort out user based on custom taxonomy term?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #41675
    alishaalisha
    Participant

    Hello,
    I am trying to sort out user based on custom taxonomy term value.
    My custom taxonomy field is cloneable.
    These are the codes:

    $meta_boxes[] = array(
    			'title' => 'Foreign University Info',
    			'type'  => 'user', // THIS: Specifically for user
    
    			'fields' => array(
    
    				array(
    					'id'     => "{$prefix}content_foreign_uni_option",
    					'type'   => 'group',
    					'clone'       => true,
    					'group_title' => 'Foreign University No.{#}', 
    					'save_state' => true,
    					'collapsible' => true,
    					'add_button' => 'Add Another University',
    					'fields' => array(
    						array(
    							'name'    => 'University',
    							'id'      => "{$prefix}funiversity",
    							'type'    => 'taxonomy_advanced',
    							'options'			=> array(
    								'taxonomy'		=> 'Foreign_Uni',
    								'type'			=> 'select_advanced',
    								'args'			=> array()
    							),
    							'placeholder'     => 'Select a Foreign University',
    							'multiple'			=> false,
    							),
    
    					),
    				),
    
    			),
    );

    I am using the codes below to sort out the user:
    $uni_name = $_POST[ 'uni_name' ]; ?>="X University"
    <?php $category = get_term_by('name', $uni_name, 'Foreign_Uni'); ?>
    <?php $funiversity_name = $category->name; ?>
    Suppose $funiversity_name="X University"
    So, I want to show all users who have "themepixels_funiversity" field value to "X University"

    $blogusers =get_users(
        array( 'role__in' => array( 'subscriber' ),
        'meta_query' => array(
                'key'     => 'themepixels_funiversity',
                'value'   => $funiversity_name,
    
            ),
        'fields' => 'all',
    )
    ); ?>

    <?php var_dump($blogusers); ?>
    But it shows all the user (Subscriber).
    Could you please help me to resolve this?
    Thanks

    #41691
    PeterPeter
    Moderator

    Hello,

    I see you are using a group field to store taxonomy values. Please notice that, using the group field to store values, not for queries. It's very hard to query posts/users by a subfield inside a group, you need to put the taxonomy field as a top field and do query users then.

    Please read more on the documentation https://metabox.io/create-group-of-custom-fields-with-meta-box-group/?swcfpc=1#how-does-the-meta-box-group-save-data

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.