Exclude pages from search

Posted in: Newspaper
Post count: 34

Hi:

I would like to know how to exclude the pages from being indexed by the search, because when using the site Search box I get results from pages that are supposed to be “hiden” from view like Homepage 3, Homepage 4 etc.

This also happen on the theme demo site.

I noted also that some plugins that are supposed to list related posts are showing pages too, when those are not supposed to appear.

Thanks

Post count: 3343

Hi,
Add this in functions.php

function remove_pages_from_search() {
    global $wp_post_types;
    $wp_post_types['page']->exclude_from_search = true;
}
add_action('init', 'remove_pages_from_search');

Thanks!

Post count: 3343

Hi,
Add this in functions.php

function remove_pages_from_search() {
    global $wp_post_types;
    $wp_post_types['page']->exclude_from_search = true;
}
add_action('init', 'remove_pages_from_search');

Thanks!

Post count: 34

Hi Marius:

that did the trick 🙂

Solved, thank you!

Post count: 18

Hi Marius,

Is it possible to exclude certain posts from search? For example using Custom Fields? I can add specific Custom Field to posts that I don’t want to find in search results. Is it possible and what would be the correct code for that?

Post count: 6600

Hi,

You can try to use this plugins for this: https://wordpress.org/plugins/search-exclude/ or you can try to search and find a solution online for this, you will need custom work for this, unfortunately we cannot offer custom work as we work hard on the development, updates, fixes and support. You can always get a freelancer from sites like: http://studio.envato.com/ if you don’t know how to do it yourself.

Thanks for the message!

Viewing 6 posts - 1 through 6 (of 6 total)
The forum ‘Newspaper’ is closed to new topics and replies.