Title: WP 2.6 get_posts
Last modified: August 19, 2016

---

# WP 2.6 get_posts

 *  Resolved 838745
 * [17 years, 10 months ago](https://wordpress.org/support/topic/wp-26-get_posts/)
 * I have 2.6 WP version. Trying to get posts from one category. Using code
 *     ```
       $args = array(
       				'post_type' => 'post',
       				'category' => $cat->cat_ID,
       				'offset' => 1,
       				'numberposts' => 2,
       				'post_status' => 'publish',
       				'orderby' => 'date',
       				'order' => 'DESC',
       				'meta_key' => 'video',
       				'meta_value' => 1);
       			        $posts = get_posts($args);
       				foreach($posts as $post)
       				{
       					setup_postdata($post);
       ...
       ```
   
 * And getting all posts from $cat->cat_ID and child cats. Any ideas how to fix?
 * query_posts is useless, since it havent support of meta_key&meta_value

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

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 10 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-826855)
 * query_posts does indeed support meta_key and meta_value in 2.6. So does the WP_Query
   method.
 * In fact, get_posts is just using WP_Query now. It’s no longer any different. 
   So switch already.
 *  Thread Starter 838745
 * [17 years, 10 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-826858)
 * Hm, how then i should use it?
    Such code doesnt work:
 *     ```
       query_posts('cat=1&metakey=video&meta_value=1&post_type=post&offset=1&numberposts=2&post_status=publish&orderdy=date&order=desc');
       				while(have_posts())
       				{
       					the_post();
       ```
   
 * Anyways, i know how to fix it to make work for me.
 * wp-includes/query.php
    line 1022: `$q['category__in'] = array_merge($q['category__in'],
   get_term_children($cat, 'category'));`
 * Just comment it and you will get directly what you asked for.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 10 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-826860)
 * “metakey” is not the same as “meta_key”. Spelling is important here…
 * Also, using category__and instead of cat might be more what you’re looking for.
   Better than hacking the core code.
 *  Thread Starter 838745
 * [17 years, 10 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-826862)
 * well. Good idea, but still not work:
 *     ```
       query_posts('cat='.$cat->cat_ID.'&meta_key=video&metavalue=1&post_type=post&offset=1&showposts=2&post_status=publish&orderdy=date&order=desc');
       				while(have_posts())
       				{
       					the_post();
       ```
   
 * Such code still give me cat and subcats posts.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 10 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-826863)
 * Yes, because the “cat” parameter gives the children as well.
 * And you misspelled “meta_value” this time.
 * Did you read what I posted about using category__and instead? Might be worth 
   looking closer at that.
 * Also, the array thing you were doing earlier with get_posts will work just as
   well with query_posts too. No need to do all that string work.
 *  Thread Starter 838745
 * [17 years, 10 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-826865)
 * Thank you man for your help.
 * Well, meta_value just was misspelled here, it works now.
    well, such code gives
   me 2nd and 3rd record i belive:
 *     ```
       $args = array(
       				'post_type' => 'post',
       				'category' => $cat->cat_ID,
       				'offset' => 1,
       				'showposts' => 2,
       				'post_status' => 'publish',
       				'orderby' => 'date',
       				'order' => 'DESC',
       				'meta_key' => 'video',
       				'meta_value' => 1);
   
       				query_posts($args);
       ```
   
 * Something else i can do?
 * And even ‘category__and’ & ‘category__’ gives same (2nd and 3rd record).
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 10 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-826869)
 * > _‘category’ => $cat->cat\_ID,_
 * …
 * Did you even try `'category__and' => array($cat->cat_ID)` at all?
 *  Thread Starter 838745
 * [17 years, 10 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-826871)
 * Wow. It finally works. Big thanks for you!
 *  [Phil Johnston](https://wordpress.org/support/users/johnstonphilip/)
 * (@johnstonphilip)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-827136)
 * Does anyone know where the function for $args sits? I am trying to figure out
   how to get the images/attachments to order based on the order I give them in 
   the admin.
    Currently they remain in the order they were uploaded even if I re-
   order them by dragging and dropping in the admin.
 * I am wondering if it has something to do with ORDER BY in the mySQL call – and
   perhaps that call is done somewhere in a function related to $args?
 *  [Phil Johnston](https://wordpress.org/support/users/johnstonphilip/)
 * (@johnstonphilip)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-827137)
 * maybe it has something to do with this:
    attachment->menu_order
 * About a minute ago it WAS showing the order of the images as they are in the 
   admin. Now they just show up as 0 for every post. I can’t see anything that has
   changed since.
 *  [Phil Johnston](https://wordpress.org/support/users/johnstonphilip/)
 * (@johnstonphilip)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-827138)
 * Got it!
 * I used a for loop and then checked against current Post Number using attachment-
   >menu_order
 * if ($currentAttachmentNum == $attachment->menu_order){

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

The topic ‘WP 2.6 get_posts’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 3 participants
 * Last reply from: [Phil Johnston](https://wordpress.org/support/users/johnstonphilip/)
 * Last activity: [17 years, 8 months ago](https://wordpress.org/support/topic/wp-26-get_posts/#post-827138)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
