我有一個WordPress的帖子類型稱爲員工目錄,列出3個bxslider轉盤中的3個不同類別的員工 - 每個帖子在li
。我有一個jQuery實時搜索過濾器,可以搜索所有3個類別。我還收到了一個查詢,其中包含該類型和類別的帖子數量,當用戶輸入搜索欄時,我需要更新帖子數量。jQuery實時搜索過濾器 - 顯示'沒有發現'的消息和更新WordPress的帖子數
我還需要在沒有結果返回時顯示一條消息,指出'No Employees Found'。
我準備在我的footer.php文檔中的JS:
// live search
$('.live-search-list li').each(function(){
$(this).attr('data-search-term', $(this).text().toLowerCase());
});
$('.live-search-box').on('keyup', function(){
var searchTerm = $(this).val().toLowerCase();
$('.live-search-list li').each(function(){
if ($(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 || searchTerm.length < 1) {
$(this).show();
} else {
$(this).hide();
}
});
});
我的WordPress迴路(有3個不同的類別都一樣):
<div class="title-count">
<h4>New Flyer</h4>
<span>
<!-- Count number of posts in type and category -->
\t <?php $args1 = array(
\t 'cat' => 2,
\t 'post_type' => 'employee-directory',
\t);
\t $the_query = new WP_Query($args1);
\t echo $the_query->found_posts; ?> People
</span>
</div>
<!-- Loop through New Flyer Category -->
<ul class="carousel">
<?php
$query1 = new WP_Query(array(
\t 'post_type' => 'employee-directory',
\t 'posts_per_page' => -1,
\t 'cat' => 2,
\t 'orderby' => 'title',
\t 'order' => 'ASC'
)
);
while ($query1->have_posts()) : $query1->the_post(); ?>
<li class="nf">
<a href="#" data-featherlight="<?php the_permalink(); ?>">
<div class="content-box">
<div class="content-image">
<?php if (has_post_thumbnail()) {
\t \t \t \t the_post_thumbnail('staff', array('class' => 'img-fluid'));
\t \t \t \t } else { ?>
<img src="<?php bloginfo('template_url'); ?>/img/placeholder_profile_photo.png" alt="<?php the_title(); ?>" />
<?php } ?>
</div>
<div class="content-info">
<h5>
<?php the_title(); ?>
</h5>
<p>
<?php the_field('position'); ?>
</p>
</div>
</div>
</a>
</li>
<?php endwhile; wp_reset_postdata(); ?>
</ul>
我知道我可以結合我的tw o查詢到一個,但由於傳送帶,我需要循環在ul
內啓動,並且後期計數和類別名稱在該循環之外,如果這樣做合理的話。
Here is a link to that page on the dev site I'm working on.
我知道我可以做一些JS if語句,但我不是很確定如何實現這一點。基本上我需要WP Query和我的JS一起工作來計算帖子,但不知道從哪裏開始。任何幫助非常感謝!