首先按自定义分类对cpt排序,然后对其余帖子进行排序

问题描述 投票:0回答:1

我正在尝试显示来自自定义帖子类型空缺的3个最新帖子。但是是否有任何帖子的自定义分类法“ option”值等于“ featured”,则应首先显示它们。

因此,如果2x帖子被标记为“精选”,那么它们将首先显示,然后仅显示最新的帖子。下面的代码将仅显示标记为“精选”的帖子,但是如果只有1或2个标记为精选的帖子,那么我将不会获得3个帖子。

任何建议将不胜感激。谢谢。

`$loop_args = array (
'post_type' => 'vacancies',
'posts_per_page' => 3,
'tax_query' => array(
   array(
  'taxonomy' => 'option',
  'field' => 'slug',
  'terms' => 'featured'
 )
 )
);
$custom_loop = new WP_Query( $loop_args );
while ( $custom_loop->have_posts() ) : $custom_loop->the_post();

$intro = get_field( 'vacancy_introduction' );
$area = get_field( 'vacancy_area' );

<?php the_title( '<h2>', '</h2>' );?>
<h3>
  <?php if( $area ): ?>
  <?php echo $area; ?>
  <?php endif; ?>
</h3>
<div>
  <?php if( $intro ): ?>
  <?php echo $intro; ?>
<?php endif; ?>
</div>

<a class="morex" href="<?php echo get_permalink(); ?>"><button><?php _e('Read More', 'tsum'); ?></button></a>

<?php endwhile; wp_reset_query(); ?>`

我正在尝试显示来自自定义帖子类型空缺的3个最新帖子。但是是否有任何帖子的自定义分类法“ option”值等于“ featured”,则应首先显示它们。 ...

wordpress sorting filter custom-post-type custom-taxonomy
1个回答
0
投票

您可以在初始循环后简单地添加。 (结束之后)

© www.soinside.com 2019 - 2024. All rights reserved.