-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
33 lines (27 loc) · 891 Bytes
/
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
<?php
function on_register_query_vars( $vars ) {
$vars[] = 'numero';
return $vars;
}
add_filter( 'query_vars', 'on_register_query_vars' );
function on_pre_get_posts( $query ) {
// check if the user is requesting an admin page
// or current query is not the main query
if ( is_admin() || ! $query->is_main_query() ){
return;
}
// edit the query only when post type is 'ressource'
// if it isn't, return
/*if ( !is_post_type_archive( 'ressource' ) ){
return;
}*/
$meta_query = array();
// add meta_query elements
if( !empty( get_query_var( 'numero' ) ) ){
$meta_query[] = array( 'key' => 'numero', 'value' => get_query_var( 'numero' ), 'compare' => '=' );
}
if( count( $meta_query ) > 0 ){
$query->set( 'meta_query', $meta_query );
}
}
add_action( 'pre_get_posts', 'on_pre_get_posts', 1 );