Last active
October 29, 2025 00:07
-
-
Save apsolut/7475d1710a709c9d0c8099ff7637279d to your computer and use it in GitHub Desktop.
exclude things in wordpress
This file contains hidden or 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 | |
| /** | |
| * https://www.wpbeginner.com/plugins/how-to-exclude-specific-pages-authors-and-more-from-wordpress-search/ | |
| */ | |
| add_action( 'pre_get_posts', 'exclude_things_from_query_bojan', 9999 ); | |
| function exclude_things_from_query_bojan( $query ) { | |
| if ( !is_admin() && $query->is_main_query() ) { | |
| if ( $query->is_search ) { | |
| $query->set('cat','-7'); // exclude category 7 u searchu,.. | |
| } | |
| // exclude category 7 svagdje (treba testirat) | |
| $query->set('cat','-7'); | |
| // exclude category id 55 | |
| $query->set('category__not_in',array(55)); | |
| // exclude post ID 44 | |
| $query->set('post__not_in',array(44)); | |
| } | |
| return $query; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment