/**
  * Modifies a WP_Query's post results by using Lift search to get the post
  * ids and returning the associated posts.  WP_Query is updated to reflect the
  * counts returned from the Lift search
  * @param array $posts
  * @param WP_Query $wp_query
  * @return array $posts
  */
 public static function _filter_posts_results($posts, $wp_query)
 {
     $lift_query = Lift_WP_Query::GetInstance($wp_query);
     if ($lift_query->has_valid_result()) {
         return $lift_query->get_posts();
     }
     return $posts;
 }
 /**
  * Lift_Search_Form constructor.
  */
 private function __construct($wp_query)
 {
     $this->lift_query = Lift_WP_Query::GetInstance($wp_query);
     $this->fields = apply_filters('lift_form_filters', array(), $this);
 }
 /**
  * Returns an array of selectable filter items
  * @param Lift_WP_Query $lift_query
  * @return array
  */
 protected function getControlItems($lift_query)
 {
     $facets = $lift_query->get_facets();
     if (empty($facets[$this->field->getName()])) {
         return array();
     }
     $my_facets = $facets[$this->field->getName()];
     $items = array();
     $selectedFound = false;
     $current_request = $this->field->bqToRequest($this->field->wpToBooleanQuery($lift_query->wp_query->query_vars));
     //$current_request = array_map( 'arrayify', $current_request );
     foreach ($my_facets as $bq_value => $count) {
         $facet_request_vars = $this->field->bqToRequest($this->field->getName() . ':' . $bq_value);
         $facet_wp_vars = $this->field->requestToWP($facet_request_vars);
         //determine if this item is selected by comparing the relative request vars to this query
         //we're assuming that these don't go further than 1 level deep
         $selected = 0 === count(array_diff_semi_assoc_recursive($facet_request_vars, $current_request));
         if ($selected) {
             $selectedFound = true;
         }
         $label = $this->field->wpToLabel($facet_wp_vars);
         if ($count) {
             $label = sprintf('%1$s (%2$d)', $label, $count);
         }
         $item = (object) array('selected' => $selected, 'value' => $facet_request_vars, 'label' => $label);
         $items[] = $item;
     }
     if (!$selectedFound) {
         $selectedBq = $this->field->wpToBooleanQuery($lift_query->wp_query->query_vars);
         if ($selectedBq) {
             $items[] = (object) array('selected' => true, 'value' => $this->field->bqToRequest($selectedBq), 'label' => sprintf('%1$s (%2$d)', $this->field->wpToLabel($lift_query->wp_query->query_vars), $lift_query->wp_query->found_posts));
         }
     }
     return $items;
 }