forked from interglobalvision/niceshirtfilms-com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
executable file
·202 lines (177 loc) · 4.99 KB
/
search.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
get_header();
/*
* Search queries
*/
$search_term = $_GET['s'];
// Request video search by 's' (default)
$video_search_default = new WP_Query( array (
'fields' => 'ids',
'post_type' => 'video',
's' => $search_term,
) );
// Request video search by 'tag'
$video_search_tag = new WP_Query( array (
'fields' => 'ids',
'post_type' => 'video',
'tag' => $search_term,
) );
// If any of the video searches have posts
if( $video_search_default->have_posts() || $video_search_tag->have_posts() ) {
// Merge IDs
$video_search_ids = array_merge( $video_search_default->posts, $video_search_tag->posts );
// Request video search query by IDs
$video_search = new WP_Query(array(
'post_type' => 'video',
'post__in' => $video_search_ids,
'orderby' => 'date',
'order' => 'DESC'
) );
} else {
// Blank query
$video_search = new WP_Query();
}
// Request directors search by 's' (default)
$director_search = new WP_Query( array (
'post_type' => 'director',
's' => $search_term
) );
// Alter main search query to only search on posts and pages
query_posts( array(
'post_type' => array( 'post', 'page' ),
's' => $search_term
) );
?>
<!-- main content -->
<main id="main-content">
<header class="page-header u-cf">
<div class="col col2 colpad1left">
<h3>Search results for '<?php echo $search_term ?>'</h3>
</div>
</header>
<?php
if( !$video_search->have_posts() && !$director_search->have_posts() && !have_posts() ) {
?>
<section class="row u-cf error">
<article class="col col2 colpad1left u-alert">
<?php _e('Sorry, nothing matched your criteria'); ?>
</article>
</section>
<?php
}
?>
<?php
if( $video_search->have_posts() ) {
?>
<section id="video-search" class="search-result-section row u-cf">
<div class="col col1">
<h4 class="search-results-label font-light-gray font-italic">Videos that matched title, brand, director, or matched a tag</h4>
</div>
<div class="col col2">
<?php
while( $video_search->have_posts() ) {
$video_search->the_post();
$img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'grid-thumb');
$imgLarge = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'grid-thumb-large');
$imgExtraLarge = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'grid-thumb-larger');
$meta = get_post_meta($post->ID);
?>
<a href="<?php echo get_video_permalink($post, $meta); ?>">
<div <?php post_class('active director-archive-video col col3 u-pointer u-background-cover u-fixed-ratio js-lazy-background'); ?>
data-vimeo-id="<?php if (!empty($meta['_vimeo_id_value'][0])) { echo $meta['_vimeo_id_value'][0];} ?>"
data-video-ratio="<?php if (!empty($meta['_vimeo_ratio_value'][0])) { echo $meta['_vimeo_ratio_value'][0];} ?>"
data-thumb="<?php echo $img[0]; ?>"
data-thumb-large="<?php echo $imgLarge[0]; ?>"
data-thumb-extra-large="<?php echo $imgExtraLarge[0]; ?>"
>
<div class="u-fixed-ratio-dummy"></div>
<div class="u-fixed-ratio-content">
<div class="u-holder">
<div class="u-held">
<h4><em><?php if (!empty($meta['_igv_title'][0])) { echo $meta['_igv_title'][0];} ?></em></h4>
<h4><?php if (!empty($meta['_igv_brand'][0])) { echo $meta['_igv_brand'][0];} ?></h4>
</div>
</div>
</div>
</div>
</a>
<?php
}
?>
</div>
</section>
<?php
}
?>
<?php
if( $director_search->have_posts() ) {
?>
<section id="director-search" class="search-result-section row u-cf">
<div class="col col1">
<h4 class="search-results-label search-results-label-fix font-light-gray font-italic">Directors that matched the criteria</h4>
</div>
<div class="col col2">
<?php
while ( $director_search->have_posts() ) {
$director_search->the_post();
$matched_content = matched_content($post);
?>
<div class="search-result copy">
<?php
if ( $matched_content ) {
?>
<a href="<?php the_permalink() ?>#biography">
<h3><?php the_title(); ?></h3>
<p><?php echo $matched_content; ?></p>
</a>
<?php
} else {
?>
<a href="<?php the_permalink() ?>">
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
</a>
<?php
}
?>
</div>
<?php
}
?>
</div>
</section>
<?php
}
?>
<?php
if( have_posts() ) {
?>
<section id="search" class="search-result-section row u-cf">
<div class="col col1">
<h4 class="search-results-label search-results-label-fix font-light-gray font-italic">Posts or pages that matched the criteria</h4>
</div>
<div class="col col2">
<?php
while( have_posts() ) {
the_post();
$meta = get_post_meta($post->ID);
?>
<article class="search-result copy">
<a href="<?php the_permalink() ?>">
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
</a>
</article>
<?php
}
?>
</div>
</section>
<?php
}
?>
<!-- end main-content -->
</main>
<?php
get_footer();
?>