如何按类别排序以下自定义帖子,如:
Cat title
玩家1
玩家2
Cat title 2
玩家5
播放器7
至于下面的代码是我的知识所在,所以任何建议都是非常感谢的!
<?php
$player_tax_terms = wp_get_object_terms( $post->ID, \'players_cat\', array(\'fields\' => \'ids\') );
$args = array(
\'post_type\' => \'players\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'players_cat\',
\'field\' => \'id\',
\'terms\' => $player_tax_terms
)
),
\'post__not_in\' => array ($post->ID),
\'meta_key\' => \'player_number\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\'
);
$related_items = new WP_Query( $args );
if ($related_items->have_posts()) : while ( $related_items->have_posts() ) : $related_items->the_post(); ?>
<a href="<?php the_permalink() ?>" class="cell player">
<?php if ( has_post_thumbnail() ): ?>
<?php the_post_thumbnail(\'thumbnail\'); ?>
<?php else: ?>
<figure class="avatar"></figure>
<?php endif; ?>
<div class="title">
<?php the_title( \'<h5>\', \'</h5>\' ) ?>
<?php if( get_field(\'player_position\') ): ?>
<p><?php the_field(\'player_position\'); ?></p>
<?php endif; ?>
</div>
<?php if( get_field(\'player_number\') ): ?>
<span><?php the_field(\'player_number\'); ?></span>
<?php endif; ?>
</a>
<?php endwhile; endif;
wp_reset_postdata();
?>
</div>
</div>