-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
63 lines (54 loc) · 1.6 KB
/
functions.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
<?php
/**
* Set parent theme styles
*/
function phpbnl18_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'phpbnl18_enqueue_styles' );
/**
* Change sort order to title on archive pages
*
* @param WP_Query $query
*
* @return WP_Query
*/
function phpbnl_change_sort_order($query){
if(is_archive() && isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'sessions'):
$query->set( 'orderby', 'meta_value');
$query->set( 'meta_key', 'session_type');
$query->set('order', 'ASC');
elseif (is_archive() && isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'speaker'):
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
endif;
return $query;
};
/**
* @param WP_Query $query
*
* @return WP_Query
*/
function phpbnl_filter_sessions($query){
if (!isset($_GET['sessions_filter'])) {
return $query;
}
if ($_GET['sessions_filter'] === 'talks') {
$filter = 'talk';
} else {
$filter = 'tutorial';
}
if(is_archive() && isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'sessions'):
$query->set('meta_query', [
'relation' => 'AND',
[
'key' => 'session_type',
'value' => $filter,
'compare' => '=',
]
]);
endif;
return $query;
}
add_action( 'pre_get_posts', 'phpbnl_change_sort_order');
add_action( 'pre_get_posts', 'phpbnl_filter_sessions');