Support » Plugins » Hacks » City Filter

  • Hello!

    I have a site with around 25 articles. What I want to do now, is filter the articles and write new one by related by cities.

    What I want is click over New York for example and every article will be about New York, but the links of the menu too.

    How can I do that in WP.

    Thanks for any advice,


Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz


    You could assign cities as either categories or tags, or create a custom taxonomy if categories and tags already have other purposes. Then the related archive pages will only show related articles.

    To alter the menu to only have related article links, hook into the ‘wp_nav_menu_items’ and remove all items not of the current category, tag, or term.

    What I thought to make referents categories and and make the relationship using the tags. Then if I link a tag city it will show everything related to this tag. But how I show the tags and at the same time make the menu linked to the same city. I do not see it clear in your answer.

    Moderator bcworkz


    You can show the tags by using the Tag Cloud widget. Clicking any tag will lead to an archive page showing all posts with that tag. Manually creating tag page links is easy too. Say you were writing an article about Warsaw and wanted to link to a tag page of the sister city Chicago. The link would look like this:

    I am assuming your menu is the one defined on the Appearance Menus Screen and your theme displays it using the wp_nav_menu() function. All the items on this menu pass through the ‘wp_nav_menu_items’ filter. Being a filter, you can write code that adds or removes menu items just before the menu is displayed.

    Your filter code could sort through all the menu items and remove any that do not have the current city tag assigned. Thus the menu only displays links related to the city the page represents.

    Thank you so much for your answer.

    Maybe you do not get my question, maybe I am missing something.

    I made a drop down menu with 10 cities. Boston, NY, etc., Every articles is filtered and shows up only thus post related to it city, like Boston or NY.

    But if I go to any other menu they are not related to this city. For example.

    I have one menu as I described above with some cities and some others links. And I have another menu with the mains links like: Nightlife, Restaurants, Travel, etc. If I link over Boston I see only the post related to Boston, but if in that page I make click again over the main links, then it shows up the everything related to this category, but does not filter the active tag or city. And this is what I do not know how to hack.

    Thanks you so much for be there reading what I post and help.

    Moderator bcworkz


    I think we are both in part not understanding the other!

    The filter I suggested works for menus added and defined through the Edit Menus admin screen.

    It will not work for other menus or any menus not using wp_nave_menu() to display the menu. How to hack those menus would depend on how that menu collects its data and displays it. If you can post the code producing such menus, I might be able to make a suggestion. If the code is more than a dozen lines, please use and provide the link here.

    If I am still misunderstanding, my apologies. A link to a typical city page and a description of what menus need filtering might help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘City Filter’ is closed to new replies.