Skip to content

Commit

Permalink
Add filter for tutorial and talks
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin de Keijzer committed Dec 19, 2018
1 parent 45dadb9 commit fcecac2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,35 @@ function phpbnl_change_sort_order($query){

return $query;
};

/**
* @param $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');

0 comments on commit fcecac2

Please sign in to comment.