Below code is an example that does what you want. See tax_query for more information.
function my_get_posts( $query ) {
// we only need to modify the query for logged in users
if ( !is_user_logged_in() ) return $query;
$current_user = wp_get_current_user();
// assuming that user's region is stored as user_region meta key
$user_region = get_user_meta( $current_user->ID, 'user_region', true );
$query->set( 'tax_query', array(
array(
'taxonomy' => 'region',
'field' => 'slug',
'terms' => $user_region
)
));
return $query;
}
add_filter( 'pre_get_posts', 'my_get_posts' );
Related Posts:
- Retrieve posts by term id custom query
- Display category posts grouped by taxonomy
- restrict_manage_posts not working in 3.3.1
- wp_query orderby title and meta key value (WP3.1)
- Looping Through Custom Tax Terms and Displaying All Posts For Each
- Taxonomy.php issue with search and filters
- How to List Parent Term Links for Custom Taxonomy With & Without Children?
- Recreating the hierarchy of taxonomies for a dropdown form menu?
- Custom taxonomy query not working with switch_to_blog
- $wpdb query a post type within a specific taxonomy term while ordering posts by custom meta value?
- Print terms with taxonomy and metabox value
- Checkbox onclick filtering on the same page
- A way to query custom taxonomies by name
- get the taxonomies terms associated with users
- Rewrite Rules returning wrong data
- Sorting main query by custom taxonomy slug
- WordPress Custom post query sorting does not work
- List related terms + taxonomies
- Search Query for Multiple Terms In Same Taxonomy
- Exclude taxonomy term from all loops, but having it on widget
- Get list of taxonomies associated with users
- query_posts that have custom taxonomy and limiting what shows based on the taxonomy
- Several taxonomy query (like filter)
- Taxonomy archive template that shows posts from more than one taxonomy
- how to access the $query variable inside taxonomy-xxx.php template file?
- Displaying Posts Attached to Custom Taxonomy Terms
- Update Custom Taxonomy Value for a post based on custom date field
- Get 1st parent category id from post
- How to get the term description in a taxonomy term archive query?
- making an index from custom taxonomies and tags of posts (not hierarchical taxonomy)
- Query Multiple Custom Taxonomies
- Query by multiple custom taxonomies
- WP Query : strange behaviour with multiple no-hierarchical tax
- WordPress search form and search result through ACF field in custom taxonomy
- Query pages by child term
- Can I use multi (sub) levels of relation (AND | OR) on custom query?
- Tax Query not working
- Custom taxonomy – query returns an error
- How to perform a search inside a specific taxonomy category
- Adding a query var to taxonomy term archive – gets redirected to the other taxonomy archive page
- add_query_arg to look up page title
- Can I use $query->set() (in a pre_get_posts() hook) with a custom taxonomy in WP 3?
- How can I query for all values of a custom taxonomies?
- query grandchildren taxonomy terms
- WP REST API no longer supports filter param, so how do I get posts in a custom taxonomy?
- Include and Exclude Taxonomies From Archives & Feeds Using ‘pre_get_posts’
- Custom Taxonomy not working with posts_per_page in new WP_query (pagination problem)
- Get value in custom field with taxonomy [closed]
- Get second level terms of custom taxonomy
- Modify Term Update Redirection
- How to get first post in a category of a custom taxonomy
- How to get the singular name of a custom taxonomy?
- Archive template for taxonomy terms
- pre_get_posts OR relation between taxonomy and author
- Custom Fields and performance
- Listing child terms of parent term
- Ajax post filter by taxonomy
- Custom Taxonomies but with Icons associated?
- Last posts from custom taxonomy
- Is it possible to create exclusive custom taxonomy?
- Custom Taxonomy Archive BUG
- how does get_term_by know which term to return when the same term appears twice in a hierarchical taxonomy?
- Changing stylesheet depending on custom taxonomy terms
- Taxonomy with_front causes all
- Why is my taxonomy template not shown?
- How Can I Change a Taxonomy URL Based On The Originating URL?
- How To Assign “Taxonomy per Taxonomy”?
- How to add a Rewrite Rule / Category Structure
- How to have two different versions of a tag/category/taxonomy archive page?
- Rewrite Rule Working for all but one of the taxonomies created
- Get custom taxonomy for visual composer shortcode but not working?
- Multi-select field for Taxonomy can’t save the value
- How to Display a menu only if it has Posts in Custom Menu?
- how does the wordpress rest API work
- Why is flush_rewrite_rules mandatory after registering custom taxonomies?
- tax_query not working
- wp_query not resetting, last post hanging
- Set term on an attachment using wp_set_object_terms and want to display the full term text but it’s showing a slug instead
- how to get term id from current post type instead of name
- Display children category images
- Dropdown taxonomy lists in admin menu
- How to define %category% for custom taxonomies?
- How to Create Multi selection search Form using Default WordPress Category Terms, and Custom post Types Taxonomies Terms?
- How do I get the correct URL?
- Cloning product not copying custom taxonomies
- deleted_$taxonomy not getting fired
- Query all images with certain tag in media library using visual portfolio plugin
- Problem with wp_list_category with custom taxomy
- Restrict viewing of posts by category, user role
- Custom order of taxonomy using wp_get_object_terms and woocommerce_term_meta
- Does a codex exist for creating meta boxes in taxonomy
- Run next query based on first query’s term
- Get the original menu item name string instead of the label
- How to use tax_query other than by slug or id or solve custom taxonomy tags conflicts with pre-existing tags?
- How to query posts that are not related to any term of a taxonomy?
- Function code problem
- add_action with variable as a part of the $tag string
- How to display Custom taxonomy on custom post listing page [duplicate]
- Rewrite URL for a specific taxonomy [duplicate]
- Template hierarchy html with taxonomy in 6.2