$terms = get_terms( 'custom_taxonomy', array(
'hide_empty' => false,
));
foreach( $terms as $term ) {
$args = [
'post_type' => 'custom_post_type',
'post_status' => 'publish',
'tax_query' => [
[
'taxonomy' => 'custom_taxonomy',
'field' => 'id',
'terms' => $term->term_id,
]
]
];
$posts = new WP_Query( $args );
$result[ $term->term_id ] = $posts->posts;
}
In result you will have associative array with
$result[ TERMID_1 ] = ARRAY( POST_OBJECT_OF_TERMID_1 );
$result[ TERMID_2 ] = ARRAY( POST_OBJECT_OF_TERMID_2 );
$result[ TERMID_3 ] = ARRAY( POST_OBJECT_OF_TERMID_3 );
Related Posts:
- How to get taxonomy term of the current page and populate queries in the template
- Custom taxonomy list page?
- What is wp_insert_term “alias_of” arg for?
- wp_set_object_terms() — prevent overwrite?
- List Hierarchical Term List with Count with Related Term
- Is there a way to set singular/plural labels for taxonomy term names?
- List taxonomy terms as links
- Get_term_by only returns one item from array
- Can we have same term slug in different taxonomies?
- Add additional data to a specific taxonomy term when used in a post
- How to have “the most used tags” taxonomy always expanded?
- Get parent and first child taxonomy terms?
- Get wordpress taxonomy archive and sort by year
- Search for tags
- Display Post by taxonomy and taxonomy child if exist
- What hooks/filters are there to alter selected terms on post save?
- Filter blog archive by category in URL
- tax_query: What to pass when I want to have all terms?
- Custom Roll/Custom Post Type – Can’t Select Categories
- Trying to list terms of a custom taxonomy using get_categories
- Add a term to an attachment submitted from front end
- Get and loop posts with all taxonomy terms
- Unable to delete a Category and Tag that share same slug
- what tables uses wp_get_post_terms
- Show list of custom taxonomies when another taxonomy is selected
- WordPress as thesaurus/dictionnary: what approach?
- List a current posts’ taxonomy terms in a widget in WordPress
- Should I be using custom post types for this or terms and taxonomies?
- How can i list the categories of a post type, the taxonomy
- Custom WP Query: force entry for some taxonomy and have others optional
- Set post terms on post publish
- How to display terms from a custom taxonomy in a hierarchy AND with custom html markup?
- How can I find the taxonomy in edited_{taxonomy}?
- Using get_posts() with tax_query parameter set isn’t working with attachments
- extend HierarchicalTermSelector function with custom renderTerms
- Searching in wordpress using wp_term_taxonomy table
- How to get the top level parent term Advanced Custom Field values in the child terms
- Allow a Taxonomy Term to be Used Only Once Across All Posts
- Pulling Data from CSV vs. pulling data from database
- Count Published & Draft Posts Associated With Each Term
- “AND” relation in custom taxonomies
- Problem with Query on Taxonomy
- get_the_term_list – Return links to edit.php instead of link to taxonomy archive template
- List posts in a category grouped by other categories?
- the_terms characters not limiting
- Hierarchical list of custom taxonomy terms
- Categorize wordpress tags
- How can i count post from my post type taxonomy
- get_term_by seems to be failing
- Blogroll links sorted by category in a table
- How to update a taxonomy term for a custom post type with auto incrementing number
- How to relate a user object to taxonomy term?
- Filtering elements by taxonomy slug
- Echo taxonomy name – second level
- Show only first child in dropdown
- Custom Post Type + Custom Taxonomy = Archive Listing Page Problems
- Taxonomy term archive default loop returns 1 record instead of 8
- Get terms in hierarchical taxonomy
- Taxonomy Checkbox Admin Panel
- Related terms – Terms that feature in post of current term
- Replacing a placeholder term with a session variable value in taxonomy filter
- Loop problem – Taxonomy
- Select query with two and two related taxonomies
- How to relate to 2 taxonomy with category
- Taxonomy Dropdown Question
- WP Search using taxonomy terms
- Customize menu link for taxonomy in WP menu
- Is possible hide hierarchical select dropdown created by jetsmartfilters? (only visual issue)
- How do I converge taxonomy category permalinks into one?
- Taxonomy terms are not checked when edit custom post
- Url leading to archive page, no matter what
- Checking if a product ID has taxonomy term attached not working with has_term
- Can I create a tax query to return posts that match two slugs from same taxonomy
- Taxonomy.php inheriting first post
- Display related terms from a taxonomy in an entry
- I want to get term by term_name without taxonomy
- Add specific content to a taxonomy results page
- Set the limit of taxonomy per page
- What is this Query? and why its taking too much time? Any way to optimize it?
- taxonomy terms, inverted
- Same page for startpage and archive?
- How to share terms between two taxonomies?
- Taxonomy Rewrite Problem
- Taxonomy terms can’t find posts from archive.php or taxonomy.php
- how to print post tags [duplicate]
- Filtering posts by taxonomy and meta_value
- What to do with shared terms splitting in WordPress 4.2?
- How to get a query odered by N of matching taxonomies?
- GET Taxonomy ID
- Hiding an Advanced Custom Field based on Taxonomy Field selection
- Non-Recursive get_term_children()
- How do I add tags/taxonomy to images + a query field on page to query ‘albums’ (images with same tag/taxonomy)
- Delete Term via edit-tags.php
- multiple taxonomies in wp_list_categories’ $args
- Description of a sub-taxonomy
- Order taxonomy terms by the frequency of use in the last 30 days
- I need to add new menu item inside the custom post admin menu
- How to orderby Taxonomy Term in a WP Query
- Hiding a tag from display
- taxonomy change to post/page type