Search code examples
wordpressloopscustom-post-type

Wordpress show all Custom Post Type except one


I am using this loop:

<?php
  $search_count = 0;
  $search = new WP_Query("s=$s & showposts=-1");

  if($search->have_posts()) : while($search->have_posts()) : $search->the_post();
    $search_count++;
  endwhile; endif;

  echo $search_count;
?>

How can I say, that I want to show every Custom Post Type, except for the post type called 'klanten' (clients in Dutch)?


Solution

  • You can use like this:

    $args = array(
        's' => $s,
        'posts_per_page' => -1,
        'post_type' => array( 'post', 'page', 'movie', 'book') // include the posts type you want to show
    );
    $query = new WP_Query( $args );
    

    Unfortunately, there's currently no way you could exclude a specific post_typeby defining it. So, the workaround is you only define the post_type you want to include.