From: Laury GvR Date: Tue, 14 Nov 2017 15:13:17 +0000 (-0500) Subject: Code was trying to grab member detail ads by city name - needed ID. Added new filter... X-Git-Tag: v1.0.6^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=2e3b530dd8a79348dfcf283072920554b7ff8b4c;p=WP-Themes%2Fmichigantrailmaps.git Code was trying to grab member detail ads by city name - needed ID. Added new filter to get city id by name --- diff --git a/functions.php b/functions.php index 7e39d70..1a1b126 100644 --- a/functions.php +++ b/functions.php @@ -70,17 +70,23 @@ add_filter('glm-member-db-front-search-query', function( $queryParts ) { } return $queryParts; }); -add_filter('get_county_by_city', function( $city ) { + +add_filter('get_city_id_by_name', function( $city ) { global $wpdb; + if (is_string($city)) { - // Could make this a subquery below but this way it only gets run on member detail pages - // where the city is not retrieved from $_REQUEST as an integer, but from $member.name as a string $citySql = "SELECT C.id FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."cities C " . "WHERE C.name = '$city' " . "LIMIT 1" . ";"; + echo $citySql; $city = $wpdb->get_var($citySql); } + return $city; +}, 10, 1); + +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 (" @@ -475,7 +481,7 @@ function display_top_ads($city, $county, $destination) { break; } switch ($city) { // Find by city first, specific list given by client - case 37: // Gaylord City + case 37: // Gaylord City echo do_shortcode("[the_ad id='1182']"); // Show Gaylord Area CVB ad break; case 89: // Petoskey City diff --git a/glm-member-db/views/front/members/detail.html b/glm-member-db/views/front/members/detail.html index eca5520..0088fdd 100644 --- a/glm-member-db/views/front/members/detail.html +++ b/glm-member-db/views/front/members/detail.html @@ -1,7 +1,7 @@
{if $member.city} - {$memberCity = $member.city} + {$memberCity = apply_filters("get_city_id_by_name", $member.city)} {$memberCounty = apply_filters("get_county_by_city", $member.city)} {else} {$memberCity = 0}