Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
MSF
/
msf-climate-hub
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
fbd3c19f
authored
2023-08-22 20:23:27 -0400
by
Jeff Balicki
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
exclude_from_search
Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent
a62eece5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
16 deletions
wp-content/themes/msf-child/inc/search-extras.php
wp-content/themes/msf-child/inc/search-extras.php
View file @
fbd3c19
...
...
@@ -10,25 +10,23 @@ function add_attachment_mime_type( $attachment_id ){
}
function
exclude_post
(
$query
)
{
if
(
$query
->
is_main_query
()
)
{
$meta_query
=
$query
->
get
(
'meta_query'
)
?
$query
->
get
(
'meta_query'
)
:
array
();
// append yours
$meta_query
[]
=
array
(
'key'
=>
'exclude_from_search'
,
// please make sure that key is correct
'value'
=>
'1'
,
'compare'
=>
'!='
// you can also try 'NOT EXISTS' comparison
);
$query
->
set
(
'meta_query'
,
$meta_query
);
}
}
add_action
(
'pre_get_posts'
,
'exclude_post'
);
function
exclude_from_search
(
$query
)
{
if
(
!
is_admin
()
&&
$query
->
is_main_query
()
&&
is_post_type_archive
(
'shows'
)
)
{
$current_meta
=
$query
->
get
(
'meta_query'
);
$custom_meta
=
array
(
'key'
=>
'exclude_from_search'
,
'type'
=>
'BINARY'
,
'value'
=>
'1'
,
'compare'
=>
'!='
);
$meta_query
=
$current_meta
[]
=
$custom_meta
;
$query
->
set
(
'meta_query'
,
array
(
$meta_query
));
}
}
add_action
(
'pre_get_posts'
,
'exclude_from_search'
);
...
...
Please
register
or
sign in
to post a comment