Here is what i whant
i have create a custom taxonomy called : type-de-partenaire
it like gold-silver-bronze (level of parnership)
and i had create a custom post type : partenaire (partnership)
I what to sort partenaire by type-de-partenaire
so here is my code
$partenaires->query( array(
'post_type'=>'partenaire',
'posts_per_page'=> '-1',
'orderby', 'meta_value',
'meta_key', 'type-de-partenaire'
) );
--
here is the result.... all the second level, shold be regroup ad the order of the first level
lien caché
now the first on is Jean-Coutu -> platine, and should be Honda -> emerites
Hi, meta_key and meta_value represent custom fields, not taxonomy terms. It is not possible to sort a WordPress query by taxonomy term. See the documentation for WP_Query Orderby here:
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
There are no options to sort WP_Query by a taxonomy term, because it is not possible. Instead, you could create a custom field with 3 options - gold, silver, and bronze. Then sort using this custom field instead of the taxonomy. If a taxonomy term is required on your site for some other reason, then you must use custom code to sync the selected term and custom field whenever the post is created or updated.
Here is my final code that work as ask... i whant to share it with the world
//======================================================================
add_shortcode( 'list_taxonomy', 'list_taxonomy' );
function list_taxonomy( $atts ) {
$output = '';
$taxonomy = $atts['taxonomy'];
$type = $atts['type'];
//get the taxonomy terms
$terms = get_terms( $taxonomy );
foreach ($terms as $term){ echo $term->name.'<br/>'; }
echo '<hr><br/>';
//compteur
//$nb = wp_count_posts('ressource');
//mam_dump($nb->publish);
foreach ($terms as $term){
$args = array(
'post_type' => $type,
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term->slug,
),
),
);
//query
$list = new WP_Query( $args );
$cpt=1;
$output .= '<h2>'.$term->name.'</h2>';
//output
while ($list->have_posts()) : $list->the_post();
$list_image = get_the_post_thumbnail_url();
$list_titre = get_the_title('');
$list_content = get_the_content('');
$list_contentfilter = apply_filters('the_content',$list_content);
//$partenaire_categorie = get_the_term_list( $partenaires->ID , 'type-de-partenaire' );
//$partenaire_categorie = strip_tags( $partenaire_categorie );
//$list_categorie = get_the_terms( $partenaires->ID, 'type-de-partenaire' );
$output .= $cpt.'-'.$list_titre.'<br/>';
$cpt++;
endwhile;
$output .= '<br/>';
}
wp_reset_postdata();
return $output;
}