What I’m trying to do (for instance):
list all the concerts which belong to
artists of the “pop” genre.
You can do it in two steps:
// 1. Get all the pop artist IDs
$artist_ids = get_posts( array(
'fields' => 'ids',
'post_type' => 'artist',
'genre' => 'pop'
) );
// 2. Get all the concerts associated to those artists
$artist_ids = implode( ',', array_map( 'absint', $artist_ids ) );
$concerts = $wpdb->get_results( "
SELECT * FROM $wpdb->posts
WHERE post_type="concert"
AND post_status="publish"
AND post_parent IN ({$artist_ids})
ORDER BY post_date DESC
" );
There’s a post_parent argument in WP_Query, but it doesn’t accept an array, hence the direct query.
Related Posts:
- how to group custom post type posts by custom taxonomy terms
- Query for posts in 2 taxonomies
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Show Post Count of a Category
- Fetch taxonomies by custom post type id array
- Query/list all terms and their custom post count
- Archive for custom taxonomy lists all posts instead of current taxonomy
- How to display Related Posts based on number of taxonomy terms matched
- How to make WP_Query not to show irrelevant posts?
- Variable not working in WP_Query
- Custom post type, custom taxonomy, query posts only from taxonomy (children of)
- Get posts by category name
- Query Multiple Custom Post Types & Exclude a Taxonomy Term
- Query Custom Post Type by Taxonomy
- Sorting the Loop by Taxonomy Value
- custom post type and a “sticky” position taxonomy
- WP_Query for custom taxonomies showing posts from non-specified terms?
- Custom Taxonomy – fields
- Displaying WordPress posts from post and custom post type in custom taxonomy
- WordPress custom post type
- How to display elements of different post types?
- How to show CPTs in term archive
- How do I get array of types associated with a taxonomy?
- Display CPT posts based on specific taxonomy
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- shortcode to show custom post types by category
- wp_set_object_terms() not adding new term to custom post and custom taxonomy
- Display all posts in main category and 1 subcategory
- Display custom post type from dynamic custom field
- Filtering WP_Query Dynamically on the Front-End
- wp_get_post_terms on custom post type with custom taxonomies returning an empty array
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Genesis filterable portfolio isotope [closed]
- wp_query check if integer exists in custom field’s array
- Wrong request query on cpt and tax
- Custom Taxonomies not appearing in Admin
- Get custom taxonomies from multiple posts
- Pagination for Custom Taxonomy Page [duplicate]
- Search / Filter posts on Title/Content OR Tags
- Custom Post Type Taxonomy Filters
- WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term
- Custom-Posttype & Custom Taxonomy WP_Query
- Custom loop with multiple taxonomy queries
- How to use custom taxonomies to reference complex relationships?
- Return one unique custom post type result when it shares a custom taxonomy in WP_QUERY?
- Query Custom posts of same taxonomy as the post itself
- Get latest 3 posts from multiple CPT in one query
- Categories of custom taxonomy don’t show any posts
- How to display custom taxonomies with links in filter menu?
- Conditional Query of Custom Post Type and custom taxonomy
- Custom Taxonomy back-end customizations
- Show a Category X’s custom post type on Category X archive page?
- Taxonomy custom post type URL
- How to Filter custom post type by taxonomy?
- Custom taxonomy rewrite give pagination 404
- Is it possible to have dedicated page for parent/child taxonomy?
- Why are taxonomy terms not saving when using custom meta boxes with radio button taxonomy selectors?
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- Custom post taxonomies as tax_query terms?
- Get related posts of child term of custom post type
- Limit amount of posts made within a custom taxonomy
- Issue on Creating Custom Tax Term Dynamically From Another CPT Meta-box On Publish
- Custom WP Query on custom meta and sort by multiple meta keys value
- list taxonomies from a custom post type
- Display a grid of taxonomy terms at root taxonomy page
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- How can I made custom taxonomies relationship?
- What’s the WP way to load remaining custom posts?
- limit value taxonomy based on previous taxonomy value wordpress
- Custom taxonomies relationship
- Several post types on WP Query by tag and taxonomy
- Polylang non-default language ignores tags in WP_Query
- How do I display the taxonomy for a custom post type in an array
- How to conditionally redirect to the post from a taxonomy page?
- How do I check if the user is on a taxonomy term parent, child or grandchild page?
- How do I display the grand child items of a taxonomy term?
- How to edit this code to get the categories in achieve page?
- Taxonomies relations
- Is it better to use WordPress Custom Post Types or Taxonomies?
- Full Custom Post Type List Organised by two Taxonomies
- WordPress Doesn’t Generate Taxonomy Archive
- How to have this permalink structure: post_type/postname/custom_inner_page
- Suggested Post and Taxonomy structure
- Query Custom Post Type Taxonomy term with multiple parameters
- First custom field value (out of several) displayed twice after query
- Custom post with more than one custom taxonomy
- Get the taxonomy of a post hierarchically
- Adding custom taxonomy in same menu place with two custom post types
- How to make custom taxonomy into drop down select in a custom metabox
- Add Custom Post Type of specific Custom Taxonomy to regularly blog loop
- How to get list of taxonomy slugs ordered parents>childs?
- WP_Query orderby and tax_query
- Different Ways to Query Custom Post Types?
- How do I share categories across multiple post types?
- Multiple tag cloud filtering
- Get url.com/post_type/taxonomy/term work!
- How to display products name in a non-alphabetical order, in a custom field (taxonomy)?
- Taxonomy in URL
- Listing all term items alphabetically / sorting loop
- Advanced search form with filters for custom taxonomies