[英]WordPress Custom Taxonomy Terms Custom Order in Dashboard & Admin Panel
[英]Wordpress Loop - Show posts from custom taxonomy terms in heirarchical order
好的,这就是我想要做的:
我有一个自定义的帖子类型,称为Drinks-menu,一种分类法,称为Drinks-menu-categories,以及一个页面模板,名为template-drinks-menu.php。
分类法中有很多术语是等级制的-葡萄酒,有白色和红色的孩子; 啤酒,比尔森啤酒,烈性黑啤酒等...
我想使用一个循环来显示这些术语中的所有帖子,并按照其在管理员中的排序顺序进行显示。 这是到目前为止我得到的代码:
<?php
$post_type = 'drinks-menu';
// Get all the taxonomies for this post type
$taxonomies = get_object_taxonomies( (object) array('post_type' => $post_type ) );
foreach( $taxonomies as $taxonomy ) :
// Gets every "category" (term) in this taxonomy to get the respective posts
$terms = get_terms( $taxonomy );
foreach( $terms as $term ) :
echo '<h1>'.$term->name.'</h1>';
if ( $term->description !== '' ) {
echo '<div class="page_summary">'. $term->description .'</div>';
}
echo '<br>';
$posts = new WP_Query( "taxonomy=$taxonomy&term=$term->slug&posts_per_page=-1&orderby=id&order=DESC" );
if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post();
?>
<a href="<?php the_permalink(); ?> "><?php the_title(); ?></a>
<?php
if( get_field( "price" ) ): ?>
<?php echo '<span">'; the_field( "price" ); echo ' | '; the_field( "abv" ); echo '</span>';?>
<?php endif;
echo '<em>'; the_excerpt(); echo '</em><br><br>';
endwhile; endif;
endforeach;
endforeach;
?>
这样可以很好地将条款中的所有帖子发布到页面上,但顺序不正确。 您可以看到我尝试了taxonomy=$taxonomy&term=$term-slug&posts_per_page=-1&orderby=id&order=DESC
但它不起作用,所有内容taxonomy=$taxonomy&term=$term-slug&posts_per_page=-1&orderby=id&order=DESC
字母顺序显示。
任何可以帮助我指出正确方向的Wordpress专家? 我希望我对这个问题很清楚。 谢谢 :-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.