Last active
September 1, 2022 13:25
-
-
Save mgibbs189/63ce2faf110b9021ca68e16a50955fc4 to your computer and use it in GitHub Desktop.
Multiple Loops for FacetWP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'post_type' => 'location', | |
'posts_per_page' => -1, | |
'order' => 'ASC', | |
'orderby' => 'title', | |
'facetwp' => true, | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'advertiser-level', | |
'field' => 'slug', | |
'terms' => array( | |
'platinum', | |
'gold', | |
'silver', | |
'bronze' | |
), | |
), | |
) | |
); | |
$posts = array(); | |
// Loop through the posts, storing data into the $posts array | |
$query = new WP_Query( $args ); | |
if ( $query->have_posts() ) { | |
while ( $query->have_posts() ) { | |
$query->the_post(); | |
$terms = wp_get_object_terms( $post->ID, 'advertiser-level', array( 'fields' => 'slugs' ) ); | |
$posts[ $terms[0] ][] = $post; | |
} | |
} | |
?> | |
<div class="entries"> | |
<div class="facetwp-template"> | |
<?php foreach ( $posts as $tier => $post_arrays ) : ?> | |
<div class="location_indv_post <?php echo $tier; ?>"> | |
<?php foreach ( $post_arrays as $post_obj ) : ?> | |
<?php setup_postdata( $post_obj ); ?> | |
<!-- PLATINUM --> | |
<?php if ( 'platinum' == $tier ) : ?> | |
Paste this code: https://gist.github.com/SauntValerian/60566a02f9f4dc5fba79af38096d4f65#file-tier-sections-php-L4-L63 | |
<?php endif; ?> | |
<!-- GOLD --> | |
<?php if ( 'gold' == $tier ) : ?> | |
Paste this code: https://gist.github.com/SauntValerian/60566a02f9f4dc5fba79af38096d4f65#file-tier-sections-php-L67-L105 | |
<?php endif; ?> | |
<!-- SILVER --> | |
<?php if ( 'platinum' == $tier ) : ?> | |
Paste this code: https://gist.github.com/SauntValerian/60566a02f9f4dc5fba79af38096d4f65#file-tier-sections-php-L109-L130 | |
<?php endif; ?> | |
<?php endforeach; ?> | |
</div> | |
<?php endforeach; ?> | |
</div> | |
</div><!-- .entries --> |
Since Facetwp v4 you can add multiple templates per page by adding "static" More explanations here = https://facetwp.com/help-center/listing-templates/listing-builder/#multiple-listing-templates-on-the-same-page
Nice!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since Facetwp v4 you can add multiple templates per page by adding "static"
More explanations here = https://facetwp.com/help-center/listing-templates/listing-builder/#multiple-listing-templates-on-the-same-page