Last active
November 14, 2016 17:23
-
-
Save svenbrier/fa5dc99df985b05948a3c22de792d300 to your computer and use it in GitHub Desktop.
SB Search Exclude Category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: SB Search Exclude Category | |
Plugin URI: https://svenbrier.de | |
Description: Für nicht angemeldete Benutzer eine Kategorie von der Anzeige in der Liste der Suchergebnisse ausschließen. | |
Version: 1.0 | |
Author: Sven Brier | |
Author URI: https://svenbrier.de | |
License: GPLv2 | |
Copyright 2016 Sven Brier (email : github@svenbrier.de) | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 2 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
add_filter( 'pre_get_posts', 'sb_sec_exclude_category' ); | |
function sb_sec_exclude_category( $query ) { | |
// If user is not logged in ... | |
if ( !is_user_logged_in() ) { | |
// ... and searching. | |
if ( $query->is_search() ) { | |
// Remove the matches from category with the ID 2. | |
$query->set('cat', '-2'); | |
return $query; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment