Title: WP_Query Problem?
Last modified: August 19, 2016

---

# WP_Query Problem?

 *  [razorharrison](https://wordpress.org/support/users/razorharrison/)
 * (@razorharrison)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/wp_query-problem-2/)
 * Guys,
 * I’m struggling with this and wondering if I am possibly missing something obvious?
 * My understanding is the the following query should spit out the posts according
   to their alphabetical order? The thing is, each catagory is a sub of cat 3. What
   I want to do is simply present all the posts according to their alphabetical 
   order. But, this dosnt seem to be happening.
 * <?php $my_query = new WP_Query(‘cat=3,-34&orderby=title&posts_per_page=500’);?
   >
 * <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <!– Do special_cat
   stuff… –>
 * The page – ie, result is here… [http://www.reviewrecruiter.com.au/reviews](http://www.reviewrecruiter.com.au/reviews)
 * Am I missing something? Please help, I havnt slept all night on this and I’m 
   about to explode ! 🙂

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

 *  [Safirul Alredha](https://wordpress.org/support/users/zeo/)
 * (@zeo)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/wp_query-problem-2/#post-1484231)
 * Easier to read, not tested but do let me know if it’s working.
 *     ```
       <?php
       $args = array(
        'cat' => array('3', '-34'),
        'orderby' => 'title',
        'posts_per_page' => '-1'
       );
   
       $my_query = new WP_Query($args); ?>
   
       <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
       <!-- Do special_cat stuff... -->
       ```
   
 *  Thread Starter [razorharrison](https://wordpress.org/support/users/razorharrison/)
 * (@razorharrison)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/wp_query-problem-2/#post-1484242)
 * Nope. That actually returns posts from ALL categories, including others outside
   of 3.
 *  [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * (@jpry)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/wp_query-problem-2/#post-1484250)
 * Instead of using “cat” as your parameter, use “post__in”. Take a look at [WP_Query()](http://codex.wordpress.org/Function_Reference/WP_Query#Example)
   in the codex to see what I mean.
 * Also, to get alphabetical order, check out [this page](http://codex.wordpress.org/Template_Tags/query_posts#Orderby_parameters).
   Looks like you want to use “orderby=title”.
 *  [Safirul Alredha](https://wordpress.org/support/users/zeo/)
 * (@zeo)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/wp_query-problem-2/#post-1484308)
 * delete:
    `'cat' => array('3', '-34'),`
 * replace with:
    `'category__not_in' => array('34'),`
 *  Thread Starter [razorharrison](https://wordpress.org/support/users/razorharrison/)
 * (@razorharrison)
 * [16 years ago](https://wordpress.org/support/topic/wp_query-problem-2/#post-1484422)
 * Thanks Zeo. I know that both methods should work but believe one of my plugins
   must be messing up the global variables.
 * To resolve this issue, I filtered the results where they spit them out by fetching
   the parent category and not displaying them if they fall into any other cat.
 * If anyone is interested, the code is;
 * <?php $category = get_the_category(); ?>
    <?php $parent = get_cat_name($category[
   0]->category_parent); ?>
 * <?php if ($parent == “FOO”) { ?>
 *  Thread Starter [razorharrison](https://wordpress.org/support/users/razorharrison/)
 * (@razorharrison)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-problem-2/#post-1484430)
 * Again this issue was not a coding issue but a server memory error.
 * Please change to resolved.

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

The topic ‘WP_Query Problem?’ 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/)
 * 6 replies
 * 3 participants
 * Last reply from: [razorharrison](https://wordpress.org/support/users/razorharrison/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-problem-2/#post-1484430)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
