IAM

OPENSOURCEFAN STUDYING
STUDYINGCOMPUTERSCIENCEANDMATH COMPUTERSCIENCE

Check out the latest superpixel benchmark — Superpixel Benchmark (2016) — and let me know your opinion! @david_stutz
12thFEBRUARY2017

SNIPPET

Simple filter to exclude specific pages (by id) from the Wordpress search.

functions.php
/**
 * Exclude pages from search.
 */
function search_exclude_pages($query) {
    if ($query->is_search && $query->is_main_query() ) {
        // exlude pages with ids ...
        $query->set('post__not_in', array(11, 3745));
    }

    return $query;
}

add_filter('pre_get_posts', 'search_exclude_pages');

What is your opinion on the code snippet? Is it working? Let me know your thoughts in the comments below or using the following platforms: