Display Query Loop items based on geolocation

I have a media query that loops through my CPT News Story items.

Each News Story CPT has an ACF true/false field called hide_in_canada.

I put my geolocation in a php variable like so:
$country = getenv('HTTP_GEOIP_COUNTRY_CODE');

If hide_in_canada is set to true, and $country = 'CA' (geolocation is Canada), I don’t want to show the News Story. Otherwise, I do want to show it.

Is this possible with Bricks’ Query Loop? If so, I’m hoping someone can point me in the right direction to figure this out.

Thanks!

1 Like

I think I figured it out a way to do it. Here are the conditions I used on my Query Loop:

Shared with CloudApp

Since I don’t know whether Brick will let me use a global variable for my country code (red box), I decided to create an ACF options field called country_code, update it with the current country code, and use it as dynamic data.

This is how I set up the options page, get the geolocation country code and set the ACF options field:

Shared with CloudApp

So I think this will work, but if anyone knows a better way to do it or sees and error here, please let me know.

1 Like