-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharchive-attraction.php
91 lines (74 loc) · 2.15 KB
/
archive-attraction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* The template for displaying archive pages of custom post types.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package Chamber
*/
// categories to pull from
$attractionCategories = array(
'arts-and-culture',
'dining',
'indoor-recreation',
'lodging',
'outdoor-recreation',
'shopping',
'local-events'
);
// number of attractions per category
$numAttractions = 12;
// our initial query for finding featured categories
$initialParams = array(
'post_type' => 'attraction',
'orderby' => 'rand',
'attraction_category' => '',
'posts_per_page' => 12,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'attr_featured',
'value' => '1',
'compare' => '='
)
)
);
$attractionsToDisplay = array();
function loopAttractions( $attractions ) {
if ( $attractions->have_posts() ) {
while ( $attractions->have_posts() ) : $attractions->the_post();
get_template_part( 'templates/archive/attraction' );
endwhile;
}
}
?>
<div id="app" class="isotope-archive">
<?php get_template_part( 'menu/isotope' ); ?>
<div class="card-grid">
<?php
foreach ( $attractionCategories as $attractionCategory ) {
$initialParams['attraction_category'] = $attractionCategory;
$initialResults = new WP_Query( $initialParams );
loopAttractions( $initialResults );
if ( $initialResults->post_count < $numAttractions ) {
// get all our post ids... i'm sure there is an easier way
$initialAttractionIds = wp_list_pluck( $initialResults->get_posts(), 'ID' );
$resultsLimit = $numAttractions - $initialResults->post_count;
$fillerParams = array(
'post_type' => 'attraction',
'orderby' => 'rand',
'post__not_in' => $initialAttractionIds,
'attraction_category' => $attractionCategory,
'posts_per_page' => $resultsLimit,
'meta_query' => array(
array( 'key' => '_thumbnail_id' )
)
);
$fillerResults = new WP_Query( $fillerParams );
loopAttractions( $fillerResults );
}
wp_reset_postdata();
}
?>
</div>
</div><!-- .isotope-archive -->