Title: WP_Querynot selecting category
Last modified: August 19, 2016

---

# WP_Querynot selecting category

 *  [WWDay3](https://wordpress.org/support/users/wwday3/)
 * (@wwday3)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/wp_querynot-selecting-category/)
 * I cloned and modified a plugin called Batch Categories. I liked what it did, 
   but I needed some additional functionality, so I made those modifications. What
   I’m having a problem with WP_Query on one particular blog. Here’s an example 
   of a query statement I’m using:
 * orderby=post_date&order=asc&post_type=post&cat=3
 * The problem is this – if I have the cat= clause in the query I return nothing
   even though the category ID exists and has posts. If I remove the cat= clause
   I get the whole file.
 * I decided to replicate the error, so I copied the plugin to another blog and 
   ran the query with one of that blog’s cats. On the second blog everything works
   as it should. So, the error seems to somehow be isolated to the first blog.
 * On that blog I’ve optimized the tables and upgraded to 2.9 to see if that would“
   fix” whatever is wrong.
 * Anybody got a clue what might be happening? Anything else I should look for?

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

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/wp_querynot-selecting-category/#post-1320509)
 * Put `$wpdb->show_errors();` just before the query and see if you get an error.
 *  Thread Starter [WWDay3](https://wordpress.org/support/users/wwday3/)
 * (@wwday3)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/wp_querynot-selecting-category/#post-1320758)
 * I added the line suggested. I get this:
 * WordPress database error: [You have an error in your SQL syntax; check the manual
   that corresponds to your MySQL server version for the right syntax to use near‘)
   WHERE 1=1 AND wp_term_taxonomy.taxonomy = ‘category’ AND wp_term_taxonomy.te’
   at line 1]
 * `SELECT SQL_CALC_FOUND_ROWS wp_posts.* , wp_croer_posts.post_rank IS NULL AS 
   isnull FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.
   object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id
   = wp_term_taxonomy.term_taxonomy_id) LEFT JOIN wp_croer_posts ON (wp_posts.ID
   = wp_croer_posts.post_id AND wp_croer_posts.cat_id = ) WHERE 1=1 AND wp_term_taxonomy.
   taxonomy = 'category' AND wp_term_taxonomy.term_id IN ('3') AND wp_posts.post_type
   = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future'
   OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.
   post_status = 'private') GROUP BY wp_posts.ID ORDER BY isnull ASC, wp_croer_posts.
   post_rank ASC, wp_posts.post_date asc LIMIT 0, 99999`
 * I have no idea what I should be looking for.
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/wp_querynot-selecting-category/#post-1320761)
 * Hey! That’s good! Errors are good. 🙂
 * A little formatting courtesy of PhpMyAdmin and the problem is obvious.
 * >  SELECT SQL_CALC_FOUND_ROWS wp_posts . * , wp_croer_posts.post_rank IS NULL
   > AS isnull
   >  FROM wp_posts INNER JOIN wp_term_relationships ON ( wp_posts.ID 
   > = wp_term_relationships.object_id ) INNER JOIN wp_term_taxonomy ON ( wp_term_relationships.
   > term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id ) LEFT JOIN wp_croer_posts
   > ON ( wp_posts.ID = wp_croer_posts.post_id AND **wp_croer_posts.cat_id = )**
   > WHERE 1 =1 AND wp_term_taxonomy.taxonomy = ‘category’ AND wp_term_taxonomy.
   > term_id IN ( ‘3’ ) AND wp_posts.post_type = ‘post’ AND ( wp_posts.post_status
   > = ‘publish’ OR wp_posts.post_status = ‘future’ OR wp_posts.post_status = ‘draft’
   > OR wp_posts.post_status = ‘pending’ OR wp_posts.post_status = ‘private’ ) GROUP
   > BY wp_posts.ID ORDER BY isnull ASC , wp_croer_posts.post_rank ASC , wp_posts.
   > post_date ASC LIMIT 0 , 99999
 * You aren’t properly passing in, or referencing, the category ID.
 *  Thread Starter [WWDay3](https://wordpress.org/support/users/wwday3/)
 * (@wwday3)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/wp_querynot-selecting-category/#post-1320799)
 * The only problem is – I cam not formatting it. I am using this code
 * $q = posts_per_page=999&orderby=post_date&order=asc&post_type=post&cat=3
 * and then
 * $query = new WP_Query;
    $wpdb->show_errors(); $posts = $query->query($q);
 * It works fine on other installs, but on this install it has the error.
 * Wht the heck is the wp_croer stuff?
 *  Thread Starter [WWDay3](https://wordpress.org/support/users/wwday3/)
 * (@wwday3)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/wp_querynot-selecting-category/#post-1320800)
 * Huh. It just started happening on another blog. Right after I installed AStickyPostOrderer.
   Once I deactivated that plugin, the query started working again.
 *  [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * (@greenshady)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/wp_querynot-selecting-category/#post-1320801)
 *     ```
       $query = new WP_Query();
       $query->query( array( 'posts_per_page' => 999, 'orderby' => 'post_date', 'order' => 'ASC', 'post_type' => 'post', 'cat' => '3' ) );
       ```
   
 *  Thread Starter [WWDay3](https://wordpress.org/support/users/wwday3/)
 * (@wwday3)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/wp_querynot-selecting-category/#post-1320802)
 * You’re saying id I passing the data via array values, instead of a url “string”,
   it will resolve the issue? OK, I’ll try it and report back.
 *  Thread Starter [WWDay3](https://wordpress.org/support/users/wwday3/)
 * (@wwday3)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/wp_querynot-selecting-category/#post-1320803)
 * Rats. I made the changes and they worked just fine. Then I activated AStickyPostOrderer,
   and the same message came up. So, I guess that plugin is to blame. Not sure if
   it’s possible to create a workaround
 *  Thread Starter [WWDay3](https://wordpress.org/support/users/wwday3/)
 * (@wwday3)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/wp_querynot-selecting-category/#post-1320808)
 * Using the array syntax as listed above, how does one do a ‘not equal’ operation?
   Also, is post_title available in the query array? Better yet – is there a place
   where I can look all of these questions up?

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

The topic ‘WP_Querynot selecting category’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 3 participants
 * Last reply from: [WWDay3](https://wordpress.org/support/users/wwday3/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/wp_querynot-selecting-category/#post-1320808)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
