<?php
$my_query = new WP_Query(array(
'post_type' => 'case',
'posts_per_page' => 2
)
);
$count = 0;
while ($my_query->have_posts()) : $my_query->the_post();
$count++;
$poster = get_field( "poster" );
$client = get_field( "client" );
$excerption = get_field( "excerption" );
if ($count == 1) {
$class = "visible-lg-block";
} else {
$class = "";
}
?>
<div class="col-md-4 col-lg-3 <?php echo $class ?> case-item">
<a href="<?php echo get_permalink(); ?>" class="case-link" style="background-image:url(<?php echo $poster;?>);">
<div class="case-inner">
<div class="category"><?php
$post_terms = wp_get_post_terms($post->ID, 'cases');
if (!empty($post_terms)) echo esc_html($post_terms[0]->name) ;
?></div>
<h3><?php the_title(); ?></h3>
<p><?php echo $excerption; ?></p>
<div class="client"><?php echo $client; ?></div>
</div>
</a>
</div>
<?php
endwhile;
wp_reset_query();
?>
$args = array(
'post_type' => 'case',
'tax_query' => array(
array(
'taxonomy' => 'category_case,
'field' => 'slug',//id категории
'terms' => $cat_name,#/id категории
),
),
);
$query = new WP_Query($args);
// Цикл
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
?>
//html
<?php
}
} else {
// Постов не найдено
}
/* Возвращаем оригинальные данные поста. Сбрасываем $post. */
wp_reset_postdata();
?>