• 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)
  • Put $wpdb->show_errors(); just before the query and see if you get an error.

    Thread Starter WWDay3

    (@wwday3)

    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.

    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

    (@wwday3)

    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

    (@wwday3)

    Huh. It just started happening on another blog. Right after I installed AStickyPostOrderer. Once I deactivated that plugin, the query started working again.

    $query = new WP_Query();
    $query->query( array( 'posts_per_page' => 999, 'orderby' => 'post_date', 'order' => 'ASC', 'post_type' => 'post', 'cat' => '3' ) );
    Thread Starter WWDay3

    (@wwday3)

    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

    (@wwday3)

    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

    (@wwday3)

    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.