Skip to content

Instantly share code, notes, and snippets.

@apsolut
Last active October 29, 2025 00:07
Show Gist options
  • Select an option

  • Save apsolut/7475d1710a709c9d0c8099ff7637279d to your computer and use it in GitHub Desktop.

Select an option

Save apsolut/7475d1710a709c9d0c8099ff7637279d to your computer and use it in GitHub Desktop.
exclude things in wordpress
<?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