• Resolved jaw23

    (@jaw23)


    Newbie here.

    How do I change my query so it includes only one post but excludes an array of categories?

    Here’s what I have but I need to change the category from 3 to a bunch of categories (and new ones which have not been created yet) so I figured the easiest way is to just exclude the ones I don’t want with an array.

    <?php $recent = new WP_Query(“cat=3&showposts=1”); while($recent->have_posts()) : $recent->the_post();?>

    I found an array but it does not specify showing only one post.

    Many thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • For example, if you do not want categories 7,12,14,15,16 you could use

    <?php $recent = new WP_Query("cat='-7,-12,-14,-15,-16'&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>

    or

    <?php
    $args = array(
      'category__not_in' => array(7,12,14,15,15),
      'showposts' => 1,
    );
    $recent = new WP_Query($args); while($recent->have_posts()) : $recent->the_post();?>

    Thread Starter jaw23

    (@jaw23)

    That’s it!
    Thanks so much!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘change query’ is closed to new replies.