Site icon Hip-Hop Website Design and Development

Utilizing get_objects_in_term in WP_User_Query to filter customers with a number of taxonomy

I’ve a web page with 3 units of choose fields which customers can every choose
a taxonomy(genre01,genre02,genre03).
After the above taxonomies are chosen, I need customers that maches all taxonomies to be displayed.
(displaying outcomes runs utilizing Ajax)

That is what I’ve up to now.

<?php
// get_objects_in_term for every taxnomy
$taxonomy = 'genre01';
$users1 = get_objects_in_term($_POST['categoryfilter'], $taxonomy);
$taxonomy2 = 'genre02';
$users2 = get_objects_in_term($_POST['categoryfilter2'], $taxonomy2);
$taxonomy3 = 'genre03';
$users3 = get_objects_in_term($_POST['categoryfilter3'], $taxonomy3);

// WP_User_Query arguments
    $args = array(
        'post_type' => 'relations',
        'order'          => 'DESC',
        'orderby'        => 'user_registered',
        'embody'   => $users1
    );

// The Person Question
$user_query = new WP_User_Query( $args );
    
    if ( ! empty( $user_query->outcomes ) ) {
         
        foreach ( $user_query->outcomes as $consumer ) {
            echo '<li><span>' . esc_html( $user->first_name ) . '</span></li>';
        }
    } 
    else {
        // no customers discovered
    }

?>

Utilizing get_objects_in_term and embody,
the above code works to an extent that customers with the chosen genre01 to be filtered and displayed
.
I could not determine a solution to embody all three get_objects_in_term values,
displaying solely customers that match all three taxnomies.

I do perceive including taxonomy to customers should not regular,
and I’d in all probability be higher off utilizing meta_query to start out with.

Any assist will likely be appreciated.