我有一个自定义的帖子类型,它将我所有的条目倒置显示,这意味着第一个条目将最后显示在我实际的首页上-有办法更改排序顺序吗?
我的代码如下:
<?php global $post; ?>
<ul class="menu-items">
<?php
$menuloop = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'menu',
'tax_query' => array(
// Note: tax_query expects an array of arrays!
array(
'taxonomy' => 'menu_type', // my guess
'field' => 'slug',
'terms' => $menuname_category
)
),
));
?>
<?php if ( have_posts() ) : while ( $menuloop->have_posts() ) : $menuloop->the_post(); ?>
<li>
<div class="grid2column"><?php the_title(); ?></div>
<div class="grid2column lastcolumn"><?php if(get_post_meta($post->ID, 'menuoption_menu_pricing', true)): ?><?php echo get_post_meta($post->ID, 'menuoption_menu_pricing', true) ?><?php endif; ?></div>
<div class="clearfix"></div>
<div class="item-description-menu"><?php echo get_the_excerpt(); ?></div>
</li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
我想你在问题中给出的代码中有一个错误。CCD_ 1。
为什么会是-1
?它必须是一个数字> 0
才能显示某些内容。
为了进行排序,您需要将这两个参数添加到数组中
array ( 'orderby' => 'date', 'order' => 'DESC'
基本上,您可以将DESC
更改为ASC
以颠倒顺序。
最终阵列
$menuloop = new WP_Query(array(
'posts_per_page' => 10,
'post_type' => 'menu',
'orderby' => 'date', // new arg
'order' => 'DESC', // new arg
'tax_query' => array(
// Note: tax_query expects an array of arrays!
array(
'taxonomy' => 'menu_type', // my guess
'field' => 'slug',
'terms' => $menuname_category
)
),
));