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?
- Display all posts in a custom post type, grouped by a custom taxonomy
- Custom Taxonomy as checkbox or dropdown
- Taxonomy: Why ‘with_front’ => false DOES NOT WORK?
- Custom Taxonomy as Dropdown in admin
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- Retrieving 3 latest post from each of 5 different custom post types
- Query posts by custom post type and custom taxonomy
- Sort the main query in subcategories/terms?
- Advanced Tax Query
- pre get posts changing the query
- Use the_taxonomies() to create a simple list
- Listing taxonomies from custom post type
- Querying CPT with Two Taxonomies
- Custom Query to display posts with custom field
- Get taxonomy description based on variable
- Pagination is not working on single-{slug}.php but works fine on page-{slug}.php
- How can i skip same post from taxonomy term?
- Filter by custom taxonomy slug on a custom post type
- Sorting multiple custom post types without a meta key/value pair by sort order
- Change or update WordPress loop based on dropdown selection
- Pagination : How to remove /page/x/ after a ‘POST’ action on a form returning to page 1
- Display custom post type from dynamic custom field
- wp_query check if integer exists in custom field’s array
- Custom-Posttype & Custom Taxonomy WP_Query
- How to display custom taxonomies with links in filter menu?
- How to Filter custom post type by taxonomy?
- Limit amount of posts made within a custom taxonomy
- Issue on Creating Custom Tax Term Dynamically From Another CPT Meta-box On Publish
- list taxonomies from a custom post type
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- What’s the WP way to load remaining custom posts?
- Taxonomies relations
- Full Custom Post Type List Organised by two Taxonomies
- Query Custom Post Type Taxonomy term with multiple parameters
- Adding custom taxonomy in same menu place with two custom post types
- pagination not working for category.php (custom post types in categories)
- Retrieve custom post types by custom taxonomies with WP_Query
- Hide specific taxonomies from a taxonomy list using ‘get_object_taxonomies’
- Using page slug in wp_query
- Custom taxonomy (categories) on custom post type return no results
- Custom taxonomy wp_query woes.
- Control content before and after custom post type loop
- Targeting categories in custom fields
- attach CPT data to a taxonomy
- Different options per post type in WP_Query
- Rewrite custom post type with taxonomy
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- My custom taxonomy is only displaying 1 of 3 terms
- Sort results without WP_QUERY?
- How to query Posts from a custom post type which contains a custom taxonomy?
- Query Posts that have Custom Taxonomy
- Custom Taxonomy Terms in Menu lead to which page?
- Using page title as a link to term archive
- How to display posttypes and taxonomy in standard posts, not in a separate label?
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- custom taxonomy pagination 404 error
- Get the taxonomy value in the post loop inside the archive page
- How to show related posts of category on post within custom posttype
- Listing all custom posts having a specific taxonomy whatever the terms
- Display custom tax in “while” loop
- Categories manage
- Showing taxonomies with terms that are attached to custom post
- Custom Taxonomy page redirecting to 404 page
- Custom post type taxonomy template and URL confusion
- Custom Taxonomy is disabled on Edit page
- Override “Parent” input for custom taxonomy
- Imported Content Doesnt Show Up On Frontend
- Loop with Custom Post Type and Taxonomies
- tax_query showing no results
- Custom post type blog pagination conflict
- How to display only taxonomies of custom post type in a page?
- Check if taxonomy is attached to at least one post in a post-type
- Looping taxonomy in taxonomy?
- Custom posts and custom taxonomies for many products and categories?
- How do i get the taxonomy term name on the CPT archive page?
- Get X posts with the same terms as the current post (custom post type and custom taxonomy)
- WP Query Conditionally query meta and taxonomy
- Assign a tag to custom post type using a query
- Show custom category archive as front page and remove taxonomy slug from urls