Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 is difficult and make the whole code-base unmaintainable. However I want to get some insight to this, since I only have experience in 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.

share|improve this question
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
add comment

2 Answers

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.

share|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
add comment
up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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