I need show posts in order by selected terms
Example:
'taxanomy' = 'My_Taxanomy',
'terms' = array(1,2,3),
So, FIRST I want show all posts with term 1, then all with term 2, .... Of course all posts in one list.
$pages = get_posts(array(
'post_type' => 'page',
'numberposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'taxonomy-name',
'field' => 'id',
'terms' => array(1,2,3) // Where term_id of Term 1 is "1".
'include_children' => false
)
)
));
Try with this
It can be like this as well
$terms = get_terms('taxonomy-name');
foreach($terms as $term) {
$posts = get_posts(array(
'tax_query' => array(
array(
'taxonomy' => 'taxonomy-name',
'field' => 'slug',
'terms' => $term->slug
)
),
'numberposts' => -1
));
foreach($posts as $post) {
// do what you want here
}
}