Support

Account

Home Forums General Issues Multi Select – Get all choices for Query Args Reply To: Multi Select – Get all choices for Query Args

  • @jarvis Thanks for that. Did add the option to choose number of posts as well so adjusted the code and am now using:

    / Variables
    $number_of_events = get_field( 'number_of_events' );
    // print_r($number_of_events);
    $event_categories = get_field('event_categories');
    $event_cat_ids = wp_list_pluck( $event_categories, 'term_id' );
    
    #$event_cat_ids = array( 1, 31 );
    
    $args = array(
    		'post_type' 		=> 'event',
    		'post_status'		=> 'publish',
    		'posts_per_page'	=> $number_of_events,
    		'order'				=> 'DESC',
    );
    			
    $args['tax_query'] = array(
    	'relation' 		=> 'OR', 
    
    	array(
    		'taxonomy'	=> 'event_category',
    		'field'		=> 'term_id',
    		'terms'		=> $event_cat_ids
    	),			
    		
    );
    
    $query = new WP_Query( $args );
    if( $query->have_posts() ) : 
    
    	while( $query->have_posts() ): $query->the_post(); ?>
    	<?php the_title(); ?>
    
    	<?php endwhile;  wp_reset_postdata();
    
    endif;
    ?>

    I see two times the one and only post for event category local.

    This when I choose 1 event and category local. So somehow things repeat themselves. Two, I see a warning

    Warning: foreach() argument must be of type array|object, null given in /Users/jasper/code/site/wp-includes/class-wp-list-util.php on line 164

    and when I print print_r($event_cat_ids); I see

    Array ( [0] => 180 )
    Event Two Local
    
    Array ( [0] => 180 )
    Event Two Local

    so closer, but not quite.