FAO: Stiofan RE: Adding London borough custom field

This topic contains 5 replies, has 3 voices, and was last updated by  Naveen Giri 4 years, 6 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #533787

    Eugene UK
    Free User
    Post count: 39

    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,
    Eugene

    #533843

    Alex Rollin
    Moderator
    Post count: 27815

    Thanks 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.

    #533965

    Eugene UK
    Free User
    Post count: 39
    This reply has been marked as private.
    #534011

    Naveen Giri
    Moderator
    Post count: 1559

    Hi 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

    #534018

    Eugene UK
    Free User
    Post count: 39

    Cheers Naveen! Nice tip.
    Gives me something to play with 🙂
    I guess another mistake is that I should be working with $postarr, not $data.

    #534347

    Naveen Giri
    Moderator
    Post count: 1559

    As its being fixed here
    https://wpgeodirectory.com/support/topic/word-capitalising-for-listing-title/#post-534174

    I will close this issue.

    Thanks for using Geodirectory Support, have a Great day.

Viewing 6 posts - 1 through 6 (of 6 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount