Nested taxonomy handling on wp_query

Question

I am using wp_query to show specific posts to users. I need to filter the posts by 2 arguments ( $artist AND $region_con ). $artist is a single value and is easy to implement in the nested handling. $region_con is an array of values.

What i want to achieve is: User is $artist and has one, or multiple $region_con values. The posts do not show, because they have just only one $region_con as taxonomy.

How can i achieve this?

function leweb_get_suggested_events() {

    // Benötigte Userdaten
    $user_id = get_current_user_id();
    $artist = get_user_meta( $user_id, 'um_musikkategorie', true);
    $region = get_user_meta( $user_id, 'um_gebiete');
    $region_con = sprintf("'%s'", implode("', '", $region[0] ) );


    echo $region_con;

    // Query
    global $wp_query;

    // Arguments  
    $args = array(
        'post_type' => 'events',
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'leweb_ct_musiker',
                'field'    => 'slug',
                'terms'    => $artist,
            ),
            array(
                'taxonomy' => 'leweb_ct_standort',
                'field'    => 'name',
                'terms'    => array( $region_con ),
            ),
        ),
    );  

    ob_start();

    $query = new WP_Query( $args );

    if( $query->have_posts() ) {
        echo '<ul>';
        while( $query->have_posts() ) {
            $query->the_post();
            $value = get_post_meta( get_the_ID(), 'event_musiker', true );
            echo '<li>' . get_the_title() . $value . '</li>';
        }
        echo '</ul>';
    }

    wp_reset_postdata();

    $output = ob_get_clean();
    return $output;

}
add_shortcode( 'leweb_suggested_events', 'leweb_get_suggested_events' );    
0
, , , LovinQuaQua 2 years 2019-10-30T19:58:01-05:00 0 Answers 71 views 0

Leave an answer

Browse
Browse