Skip to content

Instantly share code, notes, and snippets.

View Fitoussi's full-sized avatar

Eyal Fitoussi Fitoussi

View GitHub Profile
[gmw_single_location]
@Fitoussi
Fitoussi / gist:2bcaf119a0ed8b0f03f7
Last active August 29, 2015 14:18
GMW - Filter Results by State part 1
function gmw_states_dropdown( $gmw ) {
global $wpdb;
//get states exist in locations table in database
//Note that DISTINCT is being used to make sure each state called only once.
$states = $wpdb->get_col("
SELECT DISTINCT `state_long`
FROM {$wpdb->prefix}places_locator
WHERE `state_long` IS NOT NULL
@Fitoussi
Fitoussi / gist:c7a72207aec51bed1fa3
Last active August 29, 2015 14:18
GMW - Filter Results by State part 2
gmw_states_dropdown( $gmw );
@Fitoussi
Fitoussi / gist:03fdfbf4fd04bc3aada4
Last active August 29, 2015 14:18
GMW - Filter Results by State part 3
do_action( 'gmw_search_form_before_distance', $gmw );
@Fitoussi
Fitoussi / gist:8c0ac31c70518186fef3
Last active August 29, 2015 14:18
GMW - Filter Results by State part 4
function gmw_states_dropdown( $gmw ) {
global $wpdb;
//get states exist in locations table in database
//Note that DISTINCT is being used to make sure each state called only once.
$states = $wpdb->get_col("
SELECT DISTINCT `state_long`
FROM {$wpdb->prefix}places_locator
WHERE `state_long` IS NOT NULL
@Fitoussi
Fitoussi / gist:ced2430c1e8b29211061
Created April 3, 2015 08:41
GMW - Filter Results by State part 5
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;
@Fitoussi
Fitoussi / gist:b0524cba00b39834ca9c
Created May 26, 2015 08:50
array_replace_recursive for PHP < 5.3. ( http://fixthatcode.com/entry/4/show )
if ( !function_exists( 'array_replace_recursive' ) ) {
function array_replace_recursive($base, $replacements) {
foreach (array_slice(func_get_args(), 1) as $replacements) {
$bref_stack = array(&$base);
$head_stack = array($replacements);
do {
end($bref_stack);
@Fitoussi
Fitoussi / gist:c735a41e3a0833f1c2e3
Created August 10, 2015 17:52
Posts Locator Order-by Filter tutorial ( part 1 )
<?php
function gmw_orderby_dropdown( $gmw ) {
//getting the chosen value so we could pre-select the selected value after page load
$selected = ( isset( $_GET['gmw_orderby'] ) && !empty( $_GET['gmw_orderby'] ) ) ? $_GET['gmw_orderby'] : '';
?>
<select class="gmw-orderby-dropdown" name="gmw_orderby">
<option value="distance" selected="selected">Order By</option>
<option value="distance" <?php if ( $selected == 'distance' ) echo 'selected="selected"'; ?>>Distance</option>
<option value="post_title" <?php if ( $selected == 'post_title' ) echo 'selected="selected"'; ?>>Alphabetically</option>
@Fitoussi
Fitoussi / gist:db46b4eb3f330321cc3c
Created August 10, 2015 17:56
Posts Locator Order-by Filter tutorial ( part 2 )
gmw_orderby_dropdown( $gmw );
@Fitoussi
Fitoussi / gist:69f2f4672929c09c900d
Created August 10, 2015 17:57
Posts Locator Order-by Filter tutorial ( part 4 )
function gmw_orderby_dropdown( $gmw ) {
//getting the chosen value so we could pre-select the selected value after page load
$selected = ( isset( $_GET['gmw_orderby' ) && !empty( $_GET['gmw_orderby'] ) ) ? $_GET['gmw_orderby'] : '';
?>
<select class="gmw-orderby-dropdown" name="gmw_orderby">
<option value="distance" selected="selected">Distance</option>
<option value="post_title" <?php if ( $selected == 'post_title' ) echo 'selected="selected"'; ?>>Alphabetically</option>
<option value="post_date" <?php if ( $selected == 'post_date' ) echo 'selected="selected"'; ?>>Post Date</option>
<option value="post_id" <?php if ( $selected == 'post_id' ) echo 'selected="selected"'; ?>>Post ID</option>