From: Laury GvR Date: Tue, 7 Nov 2017 19:55:29 +0000 (-0500) Subject: Display ads on trail search depending on city/county selection X-Git-Tag: v1.0.0^2~6 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=c1c68ed13d94884000894279d4b344759ac25fc8;p=WP-Themes%2Fmichigantrailmaps.git Display ads on trail search depending on city/county selection --- diff --git a/functions.php b/functions.php index 94a47b9..a5f9d93 100644 --- a/functions.php +++ b/functions.php @@ -70,6 +70,21 @@ add_filter('glm-member-db-front-search-query', function( $queryParts ) { } return $queryParts; }); +add_filter('get_county_by_city', function( $city ) { + global $wpdb; + $sql = "SELECT C.id FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."counties C " + . "WHERE C.id IN (" + . "SELECT M.county " + . "FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info M " + . "WHERE M.status = 10 " + . "AND M.city = $city " + . "AND NOT M.county = 0) " + . "LIMIT 1 " + . ";"; + $results = $wpdb->get_var($sql); + return $results; + +}, 10, 1); add_filter('glm-member-db-fields-front-list-query-params', function( $query ){ $queryParams = array(); // Check for manufactures diff --git a/sections/interior-page.php b/sections/interior-page.php index 389d422..18fcff9 100644 --- a/sections/interior-page.php +++ b/sections/interior-page.php @@ -2,41 +2,49 @@
0) { + $county = apply_filters("get_county_by_city", $_REQUEST['cities'][0]); + $city = $_REQUEST['cities'][0]; + } else if (isset($_REQUEST['counties'][0]) && $_REQUEST['counties'][0] > 0) { + $county = $_REQUEST['counties'][0]; + } + switch ($city) { // Find by city first, specific list given by client + case 37: // Gaylord County echo do_shortcode("[the_ad id='1182']"); // Gaylord Area CVB break; - case 89: // Petoskey + case 89: // Petoskey County echo do_shortcode("[the_ad id='1180']"); // Petoskey Area CVB break; - case 106: // Traverse City + case 106: // Traverse City County echo do_shortcode("[the_ad id='1186']"); // Traverse City CVB break; - default: - // If no city is specified, check whether a county if specified - switch ($_REQUEST['counties'][0] ) { - case 4: // Traverse City CVB: Antrim - case 17: // Traverse City CVB: Grand Traverse - case 38: // Traverse City CVB: Leelanau - echo do_shortcode("[the_ad id='1186']"); // Traverse City CVB + default: // If a specific city override is not found, look at the county + switch ($county) { + case 40: // Crawford County + case 2: // Montmorency County + case 8: // Otsego County + echo do_shortcode("[the_ad id='1182']"); // Gaylord Area CVB break; - case 9: // Petoskey Area CVB: Charlevoix - case 13: // Petoskey Area CVB: Emmet + case 9: // Charlevoix County + case 13: // Emmet County echo do_shortcode("[the_ad id='1180']"); // Petoskey Area CVB break; - case 40: // Gaylord Area CVB: Crawford - case 2: // Gaylord Area CVB: Montmorency - case 8: // Gaylord Area CVB: Otsego - echo do_shortcode("[the_ad id='1182']"); // Gaylord Area CVB + case 4: // Antrim County + case 17: // Grand Traverse County + case 38: // Leelanau County + echo do_shortcode("[the_ad id='1186']"); // Traverse City CVB break; default: break; // No ads } break; - } ?> + } + ?>