Wordpress 首先按自定义分类法对cpt进行排序,然后按post的其余部分进行排序
我正在尝试显示自定义职位类型空缺中最近的3个职位。 但若有自定义分类法“option”值等于“featured”的帖子,那个么它们应该首先显示出来 因此,如果2x帖子被标记为“特色”,那么它们将首先显示,然后仅显示最新的帖子。 下面的代码将只显示标记为“特色”的帖子,但如果只有1或2篇文章标记为特色,我将不会看到3篇文章 任何建议都将不胜感激。 多谢各位Wordpress 首先按自定义分类法对cpt进行排序,然后按post的其余部分进行排序,wordpress,sorting,filter,custom-post-type,custom-taxonomy,Wordpress,Sorting,Filter,Custom Post Type,Custom Taxonomy,我正在尝试显示自定义职位类型空缺中最近的3个职位。 但若有自定义分类法“option”值等于“featured”的帖子,那个么它们应该首先显示出来 因此,如果2x帖子被标记为“特色”,那么它们将首先显示,然后仅显示最新的帖子。 下面的代码将只显示标记为“特色”的帖子,但如果只有1或2篇文章标记为特色,我将不会看到3篇文章 任何建议都将不胜感激。 多谢各位 `$loop_args = array ( 'post_type' => 'vacancies', 'posts_per_page' =
`$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(); ?>`
`$loop\u args=array(
“职位类型”=>“空缺”,
“每页帖子数”=>3,
“tax_query”=>数组(
排列(
“分类法”=>“选项”,
'字段'=>'段塞',
“术语”=>“特色”
)
)
);
$custom\u loop=新的WP\u查询($loop\u args);
而($custom_loop->have_posts()):$custom_loop->the_post();
$intro=get_字段(“空缺职位介绍”);
$area=获取_字段(“空缺_区域”);
`
您只需在初始循环后添加。(结束后)
但是删除您的wp\u reset\u查询
,这样您仍然可以访问计数
<?php
$count = $custom_loop->found_posts;
if ($count < 3){
$show = $count - 3;
$second_loop = array (
'post_type' => 'vacancies',
'posts_per_page' => $show,
'tax_query' => array(
array(
'taxonomy' => 'option',
'field' => 'slug',
'terms' => 'featured',
'operator' => 'NOT IN',
)
)
);
$custom2 = new WP_Query($second_loop);
while ( $custom2->have_posts() ) : $custom2->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();
}