我有一个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一起工作来计算帖子,但不知道从哪里开始。任何帮助非常感谢!