$args = array(
'post_type' => 'works',
'numberposts' => -1
);
$lastposts = get_posts( $args );
foreach( $lastposts as $post ){ setup_postdata($post);
get_template_part( 'works-item' );
}
wp_reset_postdata();
$term = get_queried_object();
$term_slug = $term->slug;
$_posts = new WP_Query( array(
'post_type' => 'works',
'posts_per_page' => 10,
'tax_query' => array(
array(
'taxonomy' => 'category', // или вашу таксономию
'field' => 'slug',
'terms' => $term_slug,
),
),
) );
if ( $_posts->have_posts() ) :
while ( $_posts->have_posts() ) :
$_posts->the_post();
get_template_part( 'works-item' );
endwhile;
endif;
wp_reset_postdata();
$tax_query = false;
$term = get_queried_object();
if ( $term instanceof WP_Term ) {
$tax_query = array(
array(
'taxonomy' => 'works-cat',
'field' => 'slug',
'terms' => $term->slug,
),
);
}
$_posts = new WP_Query( array(
'post_type' => 'works',
'posts_per_page' => 50,
'tax_query' => $tax_query,
) );
while ( $_posts->have_posts() ) : $_posts->the_post();
get_template_part( 'works-item' );
endwhile;
wp_reset_postdata();