3

Im trying to use tax_query and meta_query together to get posts. What I've read online doesn't work.

Its for a CPT and posts.

Ideally what I'd like to return is all posts and only upcoming events.

At the moment I can only seem to return either one or the other. With the code below, I'm returning the upcoming CPT only.

Any idea where I might be going wrong?

// Get the application taxonomies
        $terms = get_the_terms( $post->ID, 'cpt_taxonomy' );
        if( empty( $terms ) ) $terms = array();
        $term_ids = wp_list_pluck( $terms, 'term_id' );

        // Get todays date
        $today = date("Ymd");

        $news = get_posts([
          'post_type'         => array(
            'post',
            'tribe_events'
          ),
          'posts_per_page'    => 12,
          'post__not_in'      => array( get_the_ID() ),
          'orderby'           => 'date',
          'order'             => 'desc',
          'meta_key'          => '_EventStartDate',
          //'orderby'           => 'meta_value',
          //'order'             => 'ASC',
          'meta_query' => array(
                    array(
                      'key'         => '_EventStartDate',
                      'value'       => $today,
                      'compare'     => '>=',
                      'type'        => 'DATE'
                    )
                ),
          'tax_query'         => array(
            array(
              'taxonomy'      => 'cpt_taxonomy',
              'field'         => 'term_id',
              'terms'         => $term_ids,
              //'operator'      => 'IN'
            )
          )
        ]);
Jainil
  • 1,488
  • 1
  • 21
  • 26
  • I had the same problem and I swear nothing ever worked. I eventually lost my mind and resorted to $wpdb and just wrote the stupid query out myself. If it helps to know... tribe_events... We're both using the same plugin. Maybe that's the reason it's not working. – Kai Qing Dec 14 '18 at 16:51

0 Answers0