WP_Query
can handle all of these cases. See the section on handling multiple taxonomies.
$this_cat="interviews";
$this_tag = 'angelina-jolie';
$args = array(
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $this_cat
),
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $this_tag
)
)
);
$interviews = new WP_Query( $args );
while( $interviews->have_posts() ):
$interviews->the_post();
// normal loops stuff
endwhile;
Related Posts:
- When to use WP_query(), query_posts() and pre_get_posts
- WP Query where title begins with a specific letter
- Query Posts in a Predefined Order
- Query Custom Meta Value with Increment
- How to know which one is the main query?
- Using is_main_query to select custom post type on certain page
- WP_Query ordered by custom field that is a date string?
- get query’s query string
- Display Posts by modifying the where clause only for my query
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- How to Get All Posts but the Private ones?
- How to query ‘posts_per_page’ to display a different blog posts index template?
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- Pass the same object to multiple widgets in a template with one query
- Retrieve or Query Pages by ID
- WP query exclude post within the last month / only show over 1 month old
- WordPress query for most recent posts from multiple categories
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Too many posts cause slow load when paginating
- How can I pick a single post from the latest 3?
- Query post with meta_query where date is not in future
- Next/Prev posts on same page
- Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first
- Query with custom taxonomy not working
- Query posts by specific word on title
- How to query a custom post type with a taxonomy filter but display post type archive page?
- WP_Query last five posts, simply ordered by meta_value
- WP_Query “OR”: Find posts by ID, Name or Post Title?
- How to build a WP_Query using mulitple tags and using AND or OR operator between them
- Change query_posts to WP_Query in page but does not work
- Multiple loops without repeating content
- WP_Query condition affects posts_per_page count
- Custom Query num_rows returns wrong amount
- Serve specific “template” page at any URL that ends in its slug
- Fetch Record based on meta key dates
- add active class based on permalink and url
- Slow page loads due to WordPress Core Query
- how to make members list directory through wordpress post custom meta key.
- Add class to first post in custom loop using post_class filter
- Filtering out child category posts from parent category archive not working
- Display custom tags on pages that have a specific page parent
- Is there a better way to pull in custom content without querying posts?
- Reset WordPress Post Query to default
- Advanced WP Query and/or
- How to get all post except particular category without breaking the paging
- How do I rewrite this loop as a new WP_Query style-loop?
- Filter Custom Taxonomy Posts
- Get all posts which was posted on X Days WordPress
- How to provide meta_key array to wp_query?
- Order post type by sum of two custom fields
- Use WP_Query or query_posts() or get_posts() for optimizing a site?
- How to create custom query by keyword in post title?
- How can I comment comma-separated array values?
- Creating attachments archive in tags and categories
- 2 queries with counters
- Show single posts date, in a page of posts
- Multiple Query_Posts
- filter posts by meta key with pagination
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Custom template for password protected page
- WP_Query Class custom field parameters
- Add AJAX “Load more” on custom query block
- Posts limit on homepage (genesis framework)
- Elementor posts custom query based on tag [closed]
- Facing problem with tax_query results
- How do i create a custom post query when the meta value is an array?
- Duplice post with standard WP loop – fixed by using query_posts() instead
- ElasticPress is (aparently) messing with my search filters
- Query for current post
- Custom query to retrieve oldest post and retrieve others with date interval
- Order by meta date with a thousanth of a second defaults to post order
- Custom query for custom post type not getting correct post ID
- How to query most recent post for each author?
- Sorting query_posts() with a complex orderby filter
- How to search CPTs in draft using get_page_by_title()
- How to show post title in content editor in backend?
- Merge two queries and remove duplicate
- Seach and categories not working when ignoring sticky posts in main loop
- posts_per_page increment additional post
- Custom WP_query and integrating into theme file
- Pull posts from all categories if quantity is not met?
- Query_post 5 post first / last of post_id
- Calling body_class and wp_nav_menu for a different post
- how to exclude store in clipper theme wordpress code php
- Display post list within category list sorted by name [duplicate]
- How to organize a WP_Query’s list of posts by category and display category title?
- When should you use WP_Query vs query_posts() vs get_posts()?
- query post based on comparison
- How to query post ids liked by the Author
- Converting an existing query_posts to WP_Query
- WordPress Query showing multiple titles
- custom query to get posts
- Multiple loop for “featured” items returns wrong posts
- Query Posts to fetch Posts with Unique Tag
- Help in query for list links
- query_posts problem – need help
- WordPress pagination returns the same posts
- WP Query – Show custom posts only if user contain some user meta
- Show number of posts AND number on current page (cannot make it work)
- new WP_Query with order args – no more distinction between categories