Code was trying to grab member detail ads by city name - needed ID. Added new filter...
authorLaury GvR <laury@gaslightmedia.com>
Tue, 14 Nov 2017 15:13:17 +0000 (10:13 -0500)
committerLaury GvR <laury@gaslightmedia.com>
Tue, 14 Nov 2017 15:13:17 +0000 (10:13 -0500)
functions.php
glm-member-db/views/front/members/detail.html

index 7e39d70..1a1b126 100644 (file)
@@ -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
index eca5520..0088fdd 100644 (file)
@@ -1,7 +1,7 @@
 <div id="top-ad-container" class="row">
     
     {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}