FAO: Stiofan RE: Adding London borough custom field
This topic contains 5 replies, has 3 voices, and was last updated by Naveen Giri 6 years, 2 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
March 5, 2020 at 4:43 pm #533787
Hi Stiofan.
Sorry to bother again and again. I have a little problem to solve, and I hope you can help.
Basically, I would like to include London borough within the address, but do it programmatically. So, I have created a custom text field ‘borough’ and set it as Admin only edit.
There is this resource https://postcodes.io where you can get all location details from a postcode. So, if you search SW1A 2AA, you get json:
{ "status": 200, "result": { "postcode": "SW1A 2AA", "quality": 1, "eastings": 530047, "northings": 179951, "country": "England", "nhs_ha": "London", "longitude": -0.127695, "latitude": 51.50354, "european_electoral_region": "London", "primary_care_trust": "Westminster", "region": "London", "lsoa": "Westminster 018C", "msoa": "Westminster 018", "incode": "2AA", "outcode": "SW1A", "parliamentary_constituency": "Cities of London and Westminster", "admin_district": "Westminster", "parish": "Westminster, unparished area", "admin_county": null, "admin_ward": "St James's", "ced": null, "ccg": "NHS Central London (Westminster)", "nuts": "Westminster", "codes": { "admin_district": "E09000033", "admin_county": "E99999999", "admin_ward": "E05000644", "parish": "E43000236", "parliamentary_constituency": "E14000639", "ccg": "E38000031", "ccg_id": "09A", "ced": "E99999999", "nuts": "UKI32" } } }I am after ‘admin_district’, so I am trying this snippet, which doesn’t work:
add_filter('wp_insert_post_data','_add_borough',10,2); function _add_borough($data,$postarr){ if(isset($data['post_type']) && function_exists('geodir_get_posttypes') && in_array($data['post_type'],geodir_get_posttypes()) && isset($data['post_title'])) { if(isset($postarr['zip']) && !empty($postarr['ID'])) { $postcode = $postarr['zip']; $jsonurl = "https://api.postcodes.io/postcodes/".$postcode; $json = $this->request($jsonurl); $decoded = json_decode($json); if($decoded->status == 200){ $data['borough'] = $decoded->result->admin_district; } } } return $data; }What am I doing wrong?
Many thanks in advance,
EugeneMarch 5, 2020 at 8:42 pm #533843Thanks for writing in. We aren’t able to help with customizations, generally, as we provide the plugins as-is, but I will ask the developers if they can take a look at the code you have shared and advise on how to move ahead.
March 6, 2020 at 9:35 am #533965This reply has been marked as private.March 6, 2020 at 12:29 pm #534011Hi Eugene,
Please try wp_remote_get() instead of $this->request().
https://developer.wordpress.org/reference/functions/wp_remote_get/
Since its a customisation, you can take help of our GD experts for further need.
Thanks
March 6, 2020 at 12:41 pm #534018Cheers Naveen! Nice tip.
Gives me something to play with 🙂
I guess another mistake is that I should be working with $postarr, not $data.March 9, 2020 at 7:29 am #534347As its being fixed here
https://wpgeodirectory.com/support/topic/word-capitalising-for-listing-title/#post-534174I will close this issue.
Thanks for using Geodirectory Support, have a Great day.
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket