A WordPress plugin to add region taxonomies to users and posts. Helpers are also provided to filter posts to those that are in the same region as the signed-in user.
- Install the user-taxonomies plugin
- Install Regionalization
get_current_user_region() returns the region for the current signed-in user.
query_posts_with_current_user_region() can be called like query_posts().
<?php
// Replace
query_posts("cat=$cat&showposts=$num");
// With
query_posts_with_current_user_region("cat=$cat&showposts=$num");
?>If you like to use the pre_get_posts hook, then you can just add this
to your theme's functions.php to add the taxonomy filter to non-admin
main queries:
add_action('pre_get_posts', 'region_pre_get_posts');nav_menu_region_filtered is also provided to support filtering menu items by the current user's region. Simply:
- Add the slug name of the region to the menu's description field
- Replace with
wp_nav_menuwithnav_menu_region_filtered
<?php
// Replace
wp_nav_menu(array('theme_location' => 'main_menu', 'container_class' => 'menu-header'));
// With
nav_menu_region_filtered(array('theme_location' => 'main_menu', 'container_class' => 'menu-header'));
?>