Title: WP Query
Last modified: August 21, 2016

---

# WP Query

 *  [TA003](https://wordpress.org/support/users/ta003/)
 * (@ta003)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/)
 * Hi,
 * Having trouble with wp_query ‘category__and’. Cant get it to work.
    This is my
   code:
 *     ```
       $args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'category__and' => array( 20, 61, 74, 28 ), 'orderby' => 'date' );
       $loop = new WP_Query( $args );
   
       while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
             // Info comes here.
       <?php endwhile; ?>
       <?php wp_reset_query(); ?>
       ```
   
 * Any idea what i’m doing wrong?
    Tanks.

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/wp-query-3/page/2/?output_format=md) [→](https://wordpress.org/support/topic/wp-query-3/page/2/?output_format=md)

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835198)
 * It doesnt return any posts? Do you have posts that have all the categories assigned
   to it?
 *  [sharky1989](https://wordpress.org/support/users/sharky1989/)
 * (@sharky1989)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835204)
 * Fatal error: Class ‘WP_Query’ not found on line 2
 *  Thread Starter [TA003](https://wordpress.org/support/users/ta003/)
 * (@ta003)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835215)
 * I have a post that is assigned to all categories. I have tried it with one or
   two categories but it gave no result.
 * What can i get the posts without an error?
    The query works when i remove:’category__and’
   => array( 20, 61, 74, 28 ), but i need to get the posts that ar assigned to different
   categories. It’s an online shop with a search module… You can select a color,
   a size, …
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835221)
 * **[@sharky1989](https://wordpress.org/support/users/sharky1989/)**: It is extremely
   impolite to interrupt another poster’s ongoing thread with a question of your
   own. It causes significant problems for the forum’s volunteers and prevents us
   from being able to track issues by topic. Please [post your own topic](http://wordpress.org/support/forum/how-to-and-troubleshooting#postform).
 *  Thread Starter [TA003](https://wordpress.org/support/users/ta003/)
 * (@ta003)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835235)
 * But this is my own post?
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835237)
 * I think she meant sharky1989.
 * Does ‘category__in’ work?
    Do you have any other loops in the theme template 
   file.
 * Can you post the full code of the template file – See the[Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code)
   on how to post a large excerpt of code.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835242)
 * Sorry! My bad! 🙁
 *  Thread Starter [TA003](https://wordpress.org/support/users/ta003/)
 * (@ta003)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835258)
 * You can find the full code at this link:
    [http://pastebin.com/CKeGZisF](http://pastebin.com/CKeGZisF)
 * [@keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
    i have tried‘
   category__in’, that does not work either.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835262)
 * Maybe the posts are fetched but the shortcode doesn’t work properly. try changing
   this:
 *     ```
       $loop->post->ID
       ```
   
 * to this:
 *     ```
       $post->ID
       ```
   
 *  Thread Starter [TA003](https://wordpress.org/support/users/ta003/)
 * (@ta003)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835265)
 * That also does not work.
    The code is fine i think becaus when i change the query
   to:
 *     ```
       $args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'orderby' => 'date' );
       ```
   
 * I left out the ‘categorie_and’ and it works. So i think it is the query that 
   is not wright? But i can’t seem to figure out what is wrong.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835269)
 * Very strange.
    Can you paste this inside your loop to see if post titles are 
   showing up.
 *     ```
       <?php the_title( '<h3>', '</h3>' ); ?>
       ```
   
 *  Thread Starter [TA003](https://wordpress.org/support/users/ta003/)
 * (@ta003)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835272)
 * that doesn’t change a thing. I can’t see the titles.
 *  Thread Starter [TA003](https://wordpress.org/support/users/ta003/)
 * (@ta003)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835273)
 * Print_r from the loop:
    [http://pastebin.com/9Huj0kme](http://pastebin.com/9Huj0kme)
 * Maybe this will help?
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years ago](https://wordpress.org/support/topic/wp-query-3/#post-3835275)
 * I’m not sure why this isn’t working if you have a post with all categories assigned.
   Try it with a tax query:
 *     ```
       $args = array(
       	'post_type' => 'product',
       	'posts_per_page' => 10,
       	'orderby' => 'date',
       	'tax_query' => array(
       		array(
       			'taxonomy' => 'category',
       			'field' => 'id',
       			'terms' => array( 20, 61, 74, 28 ),
       			'operator' => 'AND'
       		)
       	)
       );
       $loop = new WP_Query( $args );
       ```
   
 * [http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters](http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters)
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [12 years, 12 months ago](https://wordpress.org/support/topic/wp-query-3/#post-3835278)
 * > Maybe this will help?
 * Yes it does. The query doesn’t include your category query by looking at the ‘
   request’ and no posts were found.
 * I think a plugin or theme is filtering the query. What plugin are you using for
   the product posts?

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/wp-query-3/page/2/?output_format=md) [→](https://wordpress.org/support/topic/wp-query-3/page/2/?output_format=md)

The topic ‘WP Query’ is closed to new replies.

## Tags

 * [wp-query](https://wordpress.org/support/topic-tag/wp-query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 18 replies
 * 4 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [12 years, 12 months ago](https://wordpress.org/support/topic/wp-query-3/page/2/#post-3835307)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
