-
-
Save pije76/00573ab71ebd8ab887efa6eb352943da 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 --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment