From 74359241fbf0e9973be2414ed196399164058f35 Mon Sep 17 00:00:00 2001 From: laury Date: Thu, 17 Jan 2019 12:56:59 -0500 Subject: [PATCH] Because Counties and Cities can be added separately, and as far as Ad priority the City is prioritised over County (but both are taken into account), in some cases the County has to be found by searching for a member with that City in the Members table, and finding out what County that member has. This means that if there is any member in the members table that has a city in the wrong county (and there is at least one), it will mess up the city/county relation. I have added an extra check that looks at the member's county before it searches through the database. What this means is that now, as long as a member has a county set, its own county will be looked at as far as which ad to pull (even if the county is wrong!) and only if it doesn't find one, uses the city to find a member in the database that has that city and grabs that member's county (again, even if it's wrong!). This also means that there is currently a member with a wrong county or city, somewhere in the database. Finding out which one it is would take deeper and more thorough investigation. --- functions.php | 15 ++++++++++++++- glm-member-db/views/front/members/detail.html | 8 ++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/functions.php b/functions.php index 4a3d69f..91dca8d 100644 --- a/functions.php +++ b/functions.php @@ -71,6 +71,19 @@ add_filter('glm-member-db-front-search-query', function( $queryParts ) { return $queryParts; }); +add_filter('get_county_id_by_name', function( $county ) { + global $wpdb; + + if (is_string($county)) { + $countySql = "SELECT C.id FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."counties C " + . "WHERE C.name = '$county' " + . "LIMIT 1" + . ";"; + $county = $wpdb->get_var($countySql); + } + return $county; +}, 10, 1); + add_filter('get_city_id_by_name', function( $city ) { global $wpdb; @@ -84,7 +97,7 @@ add_filter('get_city_id_by_name', function( $city ) { return $city; }, 10, 1); -add_filter('get_county_by_city', function( $city ) { +add_filter('get_county_id_by_city_id', function( $city ) { global $wpdb; $sql = "SELECT C.id FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."counties C " diff --git a/glm-member-db/views/front/members/detail.html b/glm-member-db/views/front/members/detail.html index 7c9f498..54e0cb8 100644 --- a/glm-member-db/views/front/members/detail.html +++ b/glm-member-db/views/front/members/detail.html @@ -2,11 +2,15 @@ {if $member.city} {$memberCity = apply_filters("get_city_id_by_name", $member.city)} - {$memberCounty = apply_filters("get_county_by_city", $memberCity)} + {if $member.county} + {$memberCounty = apply_filters("get_county_id_by_name", $member.county)} + {else} + {$memberCounty = apply_filters("get_county_id_by_city_id", $memberCity)} + {/if} {else} {$memberCity = 0} {if $member.county} - {$memberCounty = $member.county} + {$memberCounty = apply_filters("get_county_id_by_name", $member.county)} {else} {$memberCounty = 0} {/if} -- 2.17.1