These are my arguments for the search query:

$args = array(
 's' =>$s,
 'post_type' => array( 'post', 'p24_cases', 'page')

Using these arguments, the search results will show all pages that contain the search word. I want to show all pages, except for the page template called 'bedankt' (thanks in Dutch).

1 Answer 1



In order to exclude all pages with a certain template, all you need to do is to run a meta_query to exclude all pages with the custom field _wp_page_template set to bedankt. Remember, WordPress saves the template assigned to a page as a hidden custom field called _wp_page_template

With this in mind, we can do the following

$args = [
    's'         => $s,
    'post_type' => ['post', 'page', 'p24_cases'],
    'meta_key'  => [
            'key'     => '_wp_page_template',
            'value'   => 'bedankt.php',
            'compare' => 'NOT IN'

ORIGINAL ANSWER - misread question

You simply need to get the post ID of that page, anf then pass it as an array to post__not_in

'post__not_in' => [1], // Replace 1 with actual page ID

Or pre PHP 5.4

'post__not_in' => array( 1 ), // Replace 1 with actual page ID
  • Well, there are multiple pages in that template, and there is a possibility that in the future, more pages will be added. This way, I only except certain pages, but I want all pages that use the template 'bedankt' to be excepted from the query. Jun 28, 2016 at 8:56
  • AGGGHHH crap, sorry, I missed that part, sorry about that. Will rework my answer ;-) Jun 28, 2016 at 9:17
  • Haha, it's fine :p I'll see your answer soon ;) Jun 28, 2016 at 9:19
  • See my updated answer ;-) Jun 28, 2016 at 9:31
  • 2
    Yes, thank you very much! This worked like a charm. Bedank! (Dutch is not so different from Afrikaans :p) Jun 28, 2016 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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