admin管理员组

文章数量:1393090

How to query post without specific categories for example "two"and "three"

$args = array(
            'post_type' => 'post',
            'orderby' => 'date',
            'order' => 'DESC',
            'showposts' => 3);

        $category_home = new WP_Query($args);

        if($wp_query->have_posts()) :
        while($wp_query->have_posts()) :
        $wp_query->the_post(); ?>

How to query post without specific categories for example "two"and "three"

$args = array(
            'post_type' => 'post',
            'orderby' => 'date',
            'order' => 'DESC',
            'showposts' => 3);

        $category_home = new WP_Query($args);

        if($wp_query->have_posts()) :
        while($wp_query->have_posts()) :
        $wp_query->the_post(); ?>
Share Improve this question asked Feb 11, 2020 at 22:57 nabukenabuke 231 silver badge3 bronze badges 3
  • 1 have you checked developer.wordpress/reference/classes/wp_query/… ? you might need to use the category ids for this. – Michael Commented Feb 11, 2020 at 23:02
  • Are you trying to print the posts without including the category in the displayed HTML? Or trying to query posts without using categories? – Pixelsmith Commented Feb 12, 2020 at 1:14
  • @Pixelsmith trying to quert post without using categories – nabuke Commented Feb 12, 2020 at 1:18
Add a comment  | 

1 Answer 1

Reset to default 0

I solved it like this array:

        <?php
        $args = array(
          'post_type' => 'post',
            'orderby' => 'date',
              'order' => 'DESC',
          'showposts' => '3',
          'cat' => '-1,-2,-3',


        );

本文标签: Query prints posts without specific categories