/
template-faculty-search.php
254 lines (231 loc) · 7.84 KB
/
template-faculty-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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php
/**
* Template Name: Faculty Search/Directory
* Template Post Type: page
*/
?>
<?php get_header(); the_post(); ?>
<?php
$page_permalink = get_permalink();
$query = isset( $_GET['query'] ) ? sanitize_text_field( $_GET['query'] ) : '';
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$college_filter = isset( $_GET['college'] ) ? sanitize_text_field( $_GET['college'] ) : null;
$department_filter = isset( $_GET['department'] ) ? sanitize_text_field( $_GET['department'] ) : null;
$college = null;
$department = null;
// If the user explicitly filtered by college or department,
// grab the term object:
if ( $college_filter ) {
$college = get_term_by( 'slug', $college_filter, 'colleges' );
}
if ( $department_filter ) {
$department = get_term_by( 'slug', $department_filter, 'departments' );
}
// Set up baseline WP_Query args
$args = array(
'post_type' => 'person',
'meta_query' => array(
'person_type_clause' => array(
'key' => 'person_type',
'value' => 'faculty'
),
'orderby_clause' => array(
'key' => 'person_last_name',
'compare' => 'EXISTS'
)
),
'orderby' => 'orderby_clause',
'order' => 'ASC',
'paged' => $paged, // NOTE: this value must be explicitly set for paginate_links() to work properly
'posts_per_page' => 20 // NOTE: this value must be explicitly set for $faculty_wp_query->max_num_pages to be accurate when passed thru relevanssi
);
if ( $query ) {
$args['s'] = $query;
}
if ( $college || $department ) {
$args['tax_query'] = array();
}
if ( $college && $department ) {
$args['tax_query']['relation'] = 'AND';
}
if ( $college ) {
$args['tax_query'][] = array(
'taxonomy' => 'colleges',
'field' => 'term_id',
'terms' => $college->term_id
);
}
if ( $department ) {
$args['tax_query'][] = array(
'taxonomy' => 'departments',
'field' => 'term_id',
'terms' => $department->term_id
);
}
// If we're performing a search for a faculty member
// by person name and Relevanssi is enabled, use
// Relevanssi to get better search results.
// Otherwise, just initialize a new WP_Query directly.
if ( $query && function_exists( 'relevanssi_do_query' ) ) {
$faculty_wp_query = new WP_Query();
$faculty_wp_query->parse_query( $args );
relevanssi_do_query( $faculty_wp_query );
} else {
$faculty_wp_query = new WP_Query( $args );
}
?>
<div class="container mt-4 mt-md-5 pb-4 pb-md-5">
<?php the_content(); ?>
</div>
<hr role="presentation" class="my-0">
<div class="jumbotron bg-faded mb-0 px-0">
<div class="container">
<p class="lead mb-5">
<?php echo $faculty_wp_query->found_posts; ?>
result<?php if ( $faculty_wp_query->found_posts !== 1 ) { ?>s<?php } ?> found
<?php if ( $query ) : ?>
for <strong>“<?php echo stripslashes( htmlentities( $query ) ); ?>”</strong>
<?php endif; ?>
<?php if ( $department ) : ?>
in <strong><?php echo $department->name; ?></strong>
<?php endif; ?>
<?php if ( $college ) : ?>
in <strong>the <?php echo $college->name; ?></strong>
<?php endif; ?>
</p>
<?php if ( $faculty_wp_query->have_posts() ) : ?>
<ul class="list-group">
<?php
while ( $faculty_wp_query->have_posts() ) : $faculty_wp_query->the_post();
$person_titles = get_field( 'person_titles', $post->ID );
$person_colleges = get_the_terms( $post, 'colleges' );
$person_departments = get_the_terms( $post, 'departments' );
$person_tags = get_the_tags();
?>
<li class="list-group-item mb-2 mb-sm-3 py-sm-3">
<div class="row no-gutters w-100">
<div class="col-lg-8 col-xl-7">
<div class="row no-gutters position-relative w-100">
<div class="col-2 pr-3 pr-sm-4">
<div class="embed-responsive embed-responsive-1by1 media-background-container rounded-circle">
<?php
echo get_person_thumbnail(
$post,
'thumbnail',
array(
'class' => 'media-background object-fit-cover',
'alt' => '',
'style' => 'object-position: 50% 0%;',
'data-object-position' => '50% 0%'
)
);
?>
</div>
</div>
<div class="col-10 col-lg-9 align-self-center position-static py-2 py-lg-3">
<h2 class="h5 mb-0">
<a class="stretched-link" href="<?php echo get_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<?php if ( $person_titles ) : ?>
<p class="mt-1 mb-0">
<?php echo implode( ', ', array_column( $person_titles, 'job_title' ) ); ?>
</p>
<?php endif; ?>
</div>
</div>
<?php if ( $person_departments ) : ?>
<div class="offset-2 mb-2">
<div class="font-size-sm line-height-2">
<?php
foreach ( $person_departments as $k => $person_department ) :
$person_dept_filter_url = add_query_arg(
'department',
$person_department->slug,
$page_permalink
);
?>
<a href="<?php echo $person_dept_filter_url; ?>"><?php echo $person_department->name; ?></a>
<?php
if ( $k < count( $person_departments ) - 1 ) {
echo ', ';
}
?>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
<div class="col-sm-6 col-lg-4 col-xl-5 offset-2 offset-lg-0 pl-lg-5">
<?php if ( $person_colleges ) : ?>
<div class="my-2 mt-lg-5 py-sm-1 py-lg-0">
<h3 class="small font-weight-normal text-default text-uppercase mb-1 mb-sm-2">College(s)</h3>
<div class="font-size-sm line-height-2">
<?php
foreach ( $person_colleges as $k => $person_college ) :
$person_college_name = get_field( 'colleges_alias', 'colleges_' . $person_college->term_id ) ?: $person_college->name;
$person_college_filter_url = add_query_arg(
'college',
$person_college->slug,
$page_permalink
);
?>
<a href="<?php echo $person_college_filter_url; ?>"><?php echo $person_college_name; ?></a>
<?php
if ( $k < count( $person_colleges ) - 1 ) {
echo ', ';
}
?>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
<div class="col-10 col-lg offset-2 offset-lg-0 pl-lg-5 ml-lg-5">
<?php if ( is_array( $person_tags ) ) : ?>
<div class="row my-2 mt-lg-3 py-sm-1 py-lg-0">
<div class="col-lg-auto mt-lg-1">
<h3 class="small font-weight-normal text-default text-uppercase ml-lg-1 ml-xl-2 mb-0 pt-lg-2">Research Keywords</h3>
</div>
<div class="col-lg">
<ul class="list-unstyled list-inline">
<?php
foreach ( $person_tags as $person_tag ) :
$person_tag_filter_url = add_query_arg(
'query',
$person_tag->name,
$page_permalink
);
?>
<li class="list-inline-item my-1 mr-2">
<a class="badge badge-pill badge-faded letter-spacing-0 text-transform-none font-weight-normal" href="<?php echo $person_tag_filter_url; ?>">
<?php echo $person_tag->name; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php endif; ?>
</div>
</div>
</li>
<?php endwhile; ?>
</ul>
<nav aria-label="Faculty result pagination" class="mt-5">
<?php
echo paginate_links( array(
'current' => $paged,
'total' => $faculty_wp_query->max_num_pages,
'type' => 'list',
'prev_text' => '<span class="fa fa-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span>',
'next_text' => '<span class="fa fa-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span>'
) );
?>
</nav>
<?php endif; ?>
</div>
</div>
<?php wp_reset_postdata(); ?>
<?php get_footer(); ?>