-
-
Save mgibbs189/63ce2faf110b9021ca68e16a50955fc4 to your computer and use it in GitHub Desktop.
<?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 --> |
Epic!!!
How do I use this code? I do not understand very well where to put it, can you help me? Thank you
this saved me too.
1 remark/tip, to get the content parts (the_title etc....) you have to pass in the $post_obj->ID as param
🙌 freaking yes! Thanks!
FYI, on line 29, I'm using get_the_terms() instead of wp_get_object_terms() for better performance (using the object cache).
3 years later, found again this solution :-)
tip: if you don't need the default values from $post, like date created, modified, post-type, etc... you can skip the setup_postdata()
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
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!
This gist just saved my bacon. Wow. Thank you so much.