Is it theoretically possible to have the following feature?

Each post has a country code. When a visitor comes in, the system will determine the visitor's country code. Then when the page renders, only the post with that country code is displayed. This need to also affect the widgets/site search etc.

I was asked to evaluate this. I think this would lead to if statements all over the place, in the loop, and I need to modify the widgets too. All in all I think it is doable but difficult and would make the whole code-base unmaintainable. However I want to get some insight in this, since I only have experience with themes, not plugin development.

Also I am not sure how to tag this more appropriately. Any suggestion is welcomed.

UPDATE: I took a look at the 'Country Filter' plugin, it's nice but does filtering in the content level not the post level. I am also looking at add_filter(request,...) to see if this can be done at the root.

  • 1
    I think it is very much doable. You have to make a meta field for each post which will have the country information. Then you have to resolve the ip of the visitor to find the country and make the query according to this (probably with pre_get_post action). Search for IP resolving Script in google you will get enough info :) – Sisir Aug 25 '11 at 6:26

Is it theoretically possible to have the following feature?

Yes theoretically there are several Geo location API's out there, the reliable ones you have to pay for, such as MaxMind.

The latter part sounds strange, if you want the same content, then just use language files.

If for some crazy reason you want to serve up different content per country, it would be quite the undertaking, you most likely would want to create your own API or custom page per country, you dont want a billion if statements.

| improve this answer | |
  • Thanks, and yes the latter part is the part which scare the hell out of me. I am still looking at the add_filter(request...), which I hope can avoid a billion if statements. – lulalala Aug 25 '11 at 6:17

Thanks Sisir! It is pretty possible, at least I think I am 2/3 way there. By using pre_get_post action I filtered out posts successfully. This is action hook is more powerful than add_filter(request,...). There are still things I need to fix such as filtering out recent comments links related to target posts, and single post page that still displays, but I think they should be possible.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.