Support

Account

Home Forums Front-end Issues Menu Missing With Custom Filter Reply To: Menu Missing With Custom Filter

  • Nevermind I found my solution here

    I just need to wrap the function with if $query->is_main_query() statement.

     if ($query->is_main_query()){
      // get original meta query
      $meta_query = $query -> get('meta_query');
    
      // allow the url to alter the query
      // eg. ?district=1
      // eg. ?district=2
      if (isset($_GET['district']) ){
    
        $district = $_GET['district'];
        $range = explode(' - ', str_replace('$', '', $_GET['price-range']));
    
        //add meta query to the original meta queries
        $meta_query[] = array(
            'relation'  => 'AND',
            array(
            'key'       => 'district',
            'value'     => $district,
            'compare'   => 'IN',
            ),
            array(
            'key'       => 'price',
            'value'     => $range[0],
            'type'      => 'NUMERIC',
            'compare'   => '>'
            ),
            array(
            'key'       => 'price',
            'value'     => $range[1],
            'type'      => 'NUMERIC',
            'compare'   => '<'
            )
        );
    
      }
    
      // update the meta query args
      $query -> set('meta_query', $meta_query);
    
      //always return
      return;
      }