Support

Account

Home Forums General Issues How to query event post type after current date with multiple taxonomies Reply To: How to query event post type after current date with multiple taxonomies

  • Hmm,

    If events is the custom post type, then this isn’t right:
    'category_name' => 'events',

    Your meta query seems to have 2 values you’re passing in:
    'meta-value' => $value,
    'value' => $today,

    What if you combine everything into one query, something like:

    
    $args = array(
    	'post_type'			=> 'event_cpt',			
    	'posts_per_page'	=> 6,
    	
        'orderby'    => 'meta_value_num',
        'order'      => 'ASC',
        'meta_query' => array(
            array(
                'key'     => 'event_start_date',
                'value'   => $today,
    			'type' 	  => 'DATE',
                'compare' => '>=',
            ),
        ),
              	
    );
    
    $args['meta_query'] = array( 'relation' => 'AND' );	
    
    $args['tax_query'] = array(
    	'relation' 		=> 'OR', #AND
    
    	array(
    		'taxonomy'	=> 'academic_programs',
    		'field'		=> 'term_id',
    		'terms'		=> $academic_programs_id
    	),			
    		
    );
    
    $args['tax_query'] = array(
    	'relation' 		=> 'OR', #AND
    
    	array(
    		'taxonomy'	=> 'event_type',
    		'field'		=> 'term_id',
    		'terms'		=> $event_type_id
    	),			
    		
    );
    
    $query = new WP_Query( $args );
    if( $query->have_posts() ) : 
    
    	while( $query->have_posts() ): $query->the_post(); ?>
        	<span><?php $date = get_field('event_start_date');
    		$starttime = get_field('event_start_time');
    		echo $date . " - " . $starttime; ?></span></br> 
    	<?php endwhile;  wp_reset_postdata();
    
    endif;

    Code is totally untested.
    Also worth adding debugging code in:

    global $wpdb;
    
    // Print last SQL query string
    echo $wpdb->last_query;
    
    // Print last SQL query result
    echo $wpdb->last_result;
    
    // Print last SQL query Error
    echo $wpdb->last_error;

    You can see what the output of your query contains, it may then point you in the right direction