Forum

How To Exclude a Po...
 
Notifications
Clear all

How To Exclude a Post or a Pages from WordPress Search Results?

1 Posts
1 Users
1 Likes
231 Views
Rayan M
(@rayan)
Illustrious Member Admin
Topic starter
 

hi, 

You need to locate first your Functions.PHP file inside of your theme folder then paste this code inside of it.

function SearchFilter($query) {
    if ($query->is_search) {
        $query->set('cat','0,1');
    }
    return $query;
}

add_filter('pre_get_posts','SearchFilter');

 '0' & '1' are IDs, these Ids are found on your browser when you preview a specific post or a page.

ex: https://tronictalk.com/wp-admin/post.php?post=1338&action=edit this post id is:1338.

Search for IDs of the specific post or page that you want to hide from search then change '0, 1' with those Ids.

 
Posted : 19/04/2021 1:05 pm
Ronny reacted