• Resolved heartwired

    (@heartwired)


    Hey there!
    Love what you’ve done with the plugin.
    Unfortunately, I’m having an issue with getting the isoCode of Subdivisions using a shortcode.

    In your example, you show how to get the isoCode of a country:
    PHP – $userInfo->country->isoCode
    Shortcode – [geoip_detect2 property=”country.isoCode”]

    I’m trying to get the isoCode of the subdivision, but the Subdivisions object structure differs from all the others in the MaxMind GeoIP2 code. This is how the object starts:

    [subdivisions:protected] => Array
        (
            [0] => GeoIp2\Record\Subdivision Object
                (
                    [validAttributes:protected] => Array
                        (
                            [0] => confidence
                            [1] => geonameId
                            [2] => isoCode
                            [3] => names
                        )

    The other objects, such as country and city do not have the [0] => GeoIp2\Record\Subdivision Object line. This is an issue, because I’m not sure how to access the isoCode for this in a shortcode.

    I’m able to use php to print out the isoCode using $userInfo->subdivisions[0]->isoCode;
    My guess for the shortcode would be something like [geoip_detect2 property=”subdivisions.0.isoCode”] but that doesn’t work.

    Do you know of a way to access this via a shortcode?

    Hopefully that makes sense, and there’s a simple way to create a shortcode from this!
    Thanks for your help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Benjamin Pick

    (@benjamin4)

    Oh I think this case is not covered yet. Can you tell me an example IP for this?

    Thread Starter heartwired

    (@heartwired)

    Do you mean an example IP address so you can test it? I’m not sure I understand.
    Thanks for your quick reply.

    Benjamin Pick

    (@benjamin4)

    Yes – because in my country (Germany) there is only one subdivision or sometimes none at all.

    Thread Starter heartwired

    (@heartwired)

    Here’s an IP from California: 66.249.73.192
    This would return ‘CA’ for the line: $userInfo->subdivisions[0]->isoCode;

    Does that help?

    Benjamin Pick

    (@benjamin4)

    For this, you could use this shortcode (as shown on the lookup page):
    [geoip_detect2 property="mostSpecificSubdivision.isoCode"]. Is this working for you?

    Benjamin Pick

    (@benjamin4)

    Alternatively, you can use the current beta where the new shortcode syntax works.
    https://github.com/yellowtree/wp-geoip-detect/archive/master.zip

    [geoip_detect2 property=”subdivisions.0.isoCode”]

    Thread Starter heartwired

    (@heartwired)

    Awesome!
    The mostSpecificSubdivision shortcode did work.
    Thank you so much for your quick work on this. It blows my mind.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Using Subdivisions in Shortcode’ is closed to new replies.