-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunmus_search.php
More file actions
54 lines (42 loc) · 1.19 KB
/
Copy pathunmus_search.php
File metadata and controls
54 lines (42 loc) · 1.19 KB
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
<?php
/**
* Search Modifications
*
* @package unmus
*/
// Security: Stops code execution if WordPress is not loaded
if (!defined('ABSPATH')) { exit; }
/**
* Remove Quotes & Images Post Types from Search
*
* @param WP_Query The WP_Query Instance
*/
function unmus_search_exclude_post_formats( $query ) {
if( $query->is_main_query() && $query->is_search() ) {
if( ! is_admin()) {
$tax_query = array( array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'post-format-quote','post-format-image' ),
'operator' => 'NOT IN',
) );
$query->set( 'tax_query', $tax_query );
}
}
}
add_action( 'pre_get_posts', 'unmus_search_exclude_post_formats' );
/**
* Remove the WordPress Page from Search
*
* @param WP_Query The WP_Query Instance
*/
function unmus_search_filter( $query ) {
$page = get_page_by_path('wordpress',OBJECT,'page');
if($page==null){return false;}
$pageid=$page->ID;
if ( ! $query->is_admin && $query->is_search && $query->is_main_query() ) {
$query->set( 'post__not_in', array( $pageid ) );
}
}
add_action( 'pre_get_posts', 'unmus_search_filter' );
?>