Exclude in search post and include only 3 pages

you’re using $query->set('post_type', 'post'); to only include posts. What you can do is make it an array to include the post type and those specific page IDs you want.

Here’s an example code:

function custom_search_filter($query) {
    if ($query->is_search() && !is_admin() && $query->is_main_query()) {
        $query->set('post_type', 'post');
        
        // Add the IDs of the pages you want to include in search results
        $include_page_ids = array(1, 2, 3); // Replace these with your actual page IDs
        
        // Fetch current 'post__in' query var, if any
        $post_in = $query->get('post__in');
        
        // Merge existing 'post__in' with our page IDs
        if (is_array($post_in)) {
            $query->set('post__in', array_merge($post_in, $include_page_ids));
        } else {
            $query->set('post__in', $include_page_ids);
        }
    }
}

add_action('pre_get_posts', 'custom_search_filter');

The custom_search_filter function is added to the pre_get_posts action. Within the function, it’s checking if the query is a main search query that’s not within the admin area. If so, it sets the post type to ‘post’ and specifies the IDs of the pages you want to include in an array.

With this, you’d get mostly posts in your search results, plus those three key pages you want to include. Just plug in the correct page IDs in place of 1, 2, 3 and you should be good to go!

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino