Support

Account

Home Forums Front-end Issues Query with 2 parameters and 2 meta_key Reply To: Query with 2 parameters and 2 meta_key

  • You need to use nested meta queries https://make.wordpress.org/core/2014/10/20/update-on-query-improvements-in-4-1/

    and your going to need to dynamically generate the meta query. As an example the cycle portion of it might look something like this

    
    $meta_query = array('relation' => 'AND');
    if ($cycle) {
      $sub_query = array('relation' => 'OR');
      $cycles = explode(',', $cycle);
      foreach ($cycles as $cycle) {
        $sub_query[] = array(
          'key' => 'cycle',
          'value' => '"'.$cycle.'"'
          'compare' => 'LIKE'
        );
      } // end foreach cycle
      $meta_query[] = $sub_query;
    } // end if cycle
    

    Please note that the above has not been tested and is meant only as an example.

    A word of caution, too many LIKE and nested LIKE queries could time out the request.