Viewing 1 replies (of 1 total)
  • Thread Starter Marie Comet

    (@chaton666)

    Okay solved by myself :
    If intersted someone, you need to change this

    function gmw_state_filter( $clauses, $gmw ) {
    
      global $wpdb;
    
      /*
       * we first do a form check to make sure we only filter the search form that we want.
       * for this example I will use form with ID 1
       */
      if ( $gmw['ID'] != 1 )
           return $clauses;
    
      /*
       * check if a state value exists.
       * everytime the state value exists in URL the search query below will take over
       * and filter results  based on that state.
       * That is the reason we keep giving the states select box the deafult value on page load.
       * To preven visitors from having to manually change it back to deafult when
       * they want to do a proximity search based on address instead of state
       */
       if ( !isset( $_GET['gmw_state'] ) || empty( $_GET['gmw_state'] ) )
        return $clauses;
    
      //get the sate value from URL
      $state_value = $_GET['gmw_state'];
    
      //filter the tables clauses
      $clauses['fields']  = " wp_posts.*, gmwlocations.* ";
    
      //filter the WHERE cluase to look for locations with based on thier  state
      $clauses['where'] .= $wpdb->prepare(" AND gmwlocations.state_long = %s", $state_value );
    
      $clauses['groupby'] = "$wpdb->posts.ID";
    
      //order results by state name since we cannot orde rby distance
      $clauses['orderby'] = "$wpdb->posts.post_title"; 
    
      return $clauses;
    
    }
    add_filter( 'gmw_pt_location_query_clauses', 'gmw_state_filter', 99, 2 );

    By :

    function gmw_state_filter( $clauses, $gmw ) {
    
      global $wpdb;
    
      /*
       * we first do a form check to make sure we only filter the search form that we want.
       * for this example I will use form with ID 1
       */
      if ( $gmw['ID'] != 1 )
           return $clauses;
    
      /*
       * check if a state value exists.
       * everytime the state value exists in URL the search query below will take over
       * and filter results  based on that state.
       * That is the reason we keep giving the states select box the deafult value on page load.
       * To preven visitors from having to manually change it back to deafult when
       * they want to do a proximity search based on address instead of state
       */
       if ( !isset( $_GET['gmw_state'] ) || empty( $_GET['gmw_state'] ) )
        return $clauses;
    
      //get the sate value from URL
      $state_value = $_GET['gmw_state'];
    
      //filter the WHERE cluase to look for locations with based on thier  state
      $clauses['where'] .= $wpdb->prepare(" AND gmwlocations.state_long = %s", $state_value );
    
      return $clauses;
    
    }
    add_filter( 'gmw_pt_location_query_clauses', 'gmw_state_filter', 99, 2 );

Viewing 1 replies (of 1 total)
  • The topic ‘Problem with filter results by state’ is closed to new replies.