Hoping someone can assist but as part of normal WordPress theme searching, how can I add a filter as part of the search to not include certain posts/pages as part of my LOOP?

For example, I want the "Search" to ignore post=234 as part of the loop or posts 123,234,555?



you can use pre_get_posts filter hook and set the post__not_in parameter of the query ex:

function exclude_from_search_filter($query) {
        if ( !$query->is_admin && $query->is_search) {
                $query->set('post__not_in', array(40, 9) ); // id of page or post
        return $query;
add_filter( 'pre_get_posts', 'exclude_from_search_filter' );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.