I adopted a tutorial on learn how to make AJAX filters and I’ve a priority in regards to the loops. I’m utilizing bootstrap accordion to show the search ajax filters (ex. https://prnt.sc/gxrJE9_GocOl).
I’m creating some time lopp for every customized put up kind to retrieve posts associated to a search time period. I actually consider there’s a higher manner (optimization) the place I can create one loop and retailer the customized put up varieties into an array, is that this potential?
The unique directions so as to add ajax filters are right here –
https://rudrastyh.com/wordpress/ajax-post-filters.html
Right here is my code beneath:
<type motion="<?php echo site_url() ?>/wp-admin/admin-ajax.php" technique="POST" id="filter" autocomplete="off">
<enter kind="hidden" class="search-field form-control" title="s" placeholder="Search" worth="<?php echo esc_attr(get_search_query()); ?>" title="<?php _ex('Seek for:', 'label', 'wp-bootstrap-starter'); ?>">
<?php if(isset($param) && $param == 'any' || !isset($param) ) )/','', $_all_any_video_term__);
$all_any_video_term = str_replace(' ', '-', $_all_any_video_term);
echo '<div class="form-check form-input-video">
<enter class="form-check-input taxfilter" kind="radio" id="'.$all_any_video_term.'" title="categoryfilter" worth="'.$all_any_video_id.'" />
<label class="form-check-label" for="'.$all_any_video_term.'">'.$__all_any_video_term.'</label>
</div>';
endforeach; ?>
</div><!-- accordion-body -->
</div> <!-- accordion-collapse -->
</div> <!-- accordion-item -->
<?php
else:
echo '<h3>movies</h3>';
echo 'No classes discovered';
endif; //search all any video if
?>
<?php
$search_all_any_font_args = $search_args;
$search_all_any_font_args['posts_per_page'] = -1;
$search_all_any_font_args['post_type'] = 'font';
$search_all_any_font = new WP_Query( $search_all_any_font_args );
if ( $search_all_any_font->have_posts() ) : ?>
<div class="accordion-item">
<h2 class="accordion-header" id="headingFont">
<button class="accordion-button" kind="button" data-bs-toggle="collapse" data-bs-target="#collapseFont" aria-expanded="true" aria-controls="collapseFont">
Fonts
</button>
</h2>
<div id="collapseFont" class="accordion-collapse collapse present" aria-labelledby="headingFont" data-bs-parent="#accordionCategories">
<div class="accordion-body">
<?php
$all_any_font_term_names = array();
$all_any_font_term_ids = array();
whereas ( $search_all_any_font->have_posts() ) : $search_all_any_font->the_post();
$post_id = get_the_ID();
$all_any_font_taxs = get_the_terms($post_id, 'font_cat');
if ( ! is_wp_error( $all_any_font_taxs ) && ! empty( $all_any_font_taxs ) ) :
foreach($all_any_font_taxs as $all_any_font_tax) :
$all_any_font_term_names[] = $all_any_font_tax->title;
$all_any_font_term_ids[] = $all_any_font_tax->term_id;
endforeach;
endif;
endwhile;
$all_any_font_terms = array_unique($all_any_font_term_names, SORT_REGULAR);
$all_any_font_ids = array_unique($all_any_font_term_ids, SORT_REGULAR);
foreach(array_combine($all_any_font_ids, $all_any_font_terms) as $all_any_font_id => $__all_any_font_term):
$_all_any_font_term__ = strtolower($__all_any_font_term);
$_all_any_font_term = preg_replace('/( elseif(isset($param) && $param == 'snipp') )/','',$_snipp_term__);
$snipp_term = str_replace(' ', '-', $_snipp_term);
echo '<div class="form-check form-input-snipp">
<enter class="form-check-input taxfilter" kind="radio" id="'.$snipp_term.'" title="categoryfilter" worth="'.$snipp_id.'" />
<label class="form-check-label" for="'.$snipp_term.'">'.$__snipp_term.'</label>
</div>';
endforeach;
endif; //search snipp if
?>
<?php elseif(isset($param) && $param == 'font') )/','',$_font_term__);
$font_term = str_replace(' ', '-', $_font_term);
echo '<div class="form-check form-input-font">
<enter class="form-check-input taxfilter" kind="radio" id="'.$font_term.'" title="categoryfilter" worth="'.$font_id.'" />
<label class="form-check-label" for="'.$font_term.'">'.$__font_term.'</label>
</div>';
endforeach;
endif; // search font if
?>
<?php elseif(isset($param) && $param == 'put up') )/','',$_blog_term__);
$blog_term = str_replace(' ', '-', $_blog_term);
echo '<div class="form-check form-input-blog">
<enter class="form-check-input taxfilter" kind="radio" id="'.$blog_term.'" title="categoryfilter" worth="'.$blog_id.'" />
<label class="form-check-label" for="'.$blog_term.'">'.$__blog_term.'</label>
</div>';
endforeach;
endif; // search weblog if
?>
<?php elseif(isset($param) && $param == 'picture') )/','',$_photo_term__);
$photo_term = str_replace(' ', '-', $_photo_term);
echo '<div class="form-check form-input-photo">
<enter class="form-check-input taxfilter" kind="radio" id="'.$photo_term.'" title="categoryfilter" worth="'.$photo_id.'" />
<label class="form-check-label" for="'.$photo_term.'">'.$__photo_term.'</label>
</div>';
endforeach;
endif; // search picture if
?>
<?php elseif(isset($param) && $param == 'video') )/','',$_video_term__);
$video_term = str_replace(' ', '-', $_video_term);
echo '<div class="form-check form-input-video">
<enter class="form-check-input taxfilter" kind="radio" id="'.$video_term.'" title="categoryfilter" worth="'.$video_id.'" />
<label class="form-check-label" for="'.$video_term.'">'.$__video_term.'</label>
</div>';
endforeach;
endif; // search video if
?>
<?php
else {
echo 'No Classes obtainable presently.';
}//else
?>
<enter kind="hidden" title="motion" worth="myfilter">
</type> <!-- type -->