如何查询所有术语和顺序 DESC



我想显示帖子有分类tag_year并订购 DESC,但我的代码不显示

$term = get_terms('tag_year');
$query_year = array(
'post_type'     =>  'post',
'post_status'   => 'publish',
'tax_query'     =>  array(
array(
'taxonomy' =>  'tag_year',
'field'    =>  'slug',
'terms'    =>  $term->slug,
),
),
'order' =>  'DESC'
);
$query = new WP_Query($query_year);

试试这个:

$terms  = get_terms('tag_year');
tax_map = array();
foreach ( $terms as $term ) {
$tax_map[] = $term->slug;
}
$query_year = array(
'post_type'     =>  'post',
'post_status'   => 'publish',
'tax_query'     =>  array(
array(
'taxonomy' =>  'tag_year',
'field'    =>  'slug',
'terms'    =>  $tax_map,
'operator' =>  'IN',
),
),
'order' =>  'DESC'
);
$query = new WP_Query($query_year);
$custom_terms = get_terms('your_term_name');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'career',
'tax_query' => array(
array(
'taxonomy' => 'your_term_name',
'field' => 'slug',
'terms' => $custom_term->slug,
'order' => DESC
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts())
{ ?>
<h2><?php echo $custom_term->name.</h2>
<?php  while($loop->have_posts())
{ $loop->the_post(); ?>
<h2> <a href="<?php the_permalink()?>"><?php the_title()?></a></h2><br>
<p><?php the_excerpt();?></p>
<?php 
}
}
}

最新更新