Title: get_posts isn&#8217;t working right
Last modified: August 18, 2016

---

# get_posts isn’t working right

 *  [tau_ceti](https://wordpress.org/support/users/tau_ceti/)
 * (@tau_ceti)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/get_posts-isnt-working-right/)
 * I’m using the following code in a function called by my sidebar:
 * `
    $posts = get_posts('category='.$cat.'&order=DESC&orderby=post_date'); foreach(
   $posts as $post) : start_wp(); // does a bunch of stuff endforeach;
 * When I copy the code directly into the sidebar it works fine. When it’s embedded
   within the function, calls like the_date() and the_title() return my most recent
   posts (rather than those called for by the get_posts above). $post->ID gets me
   the ids I want, so I know there’s nothing wrong with get_posts. Anyone know what’s
   going on?

The topic ‘get_posts isn’t working right’ 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/)
 * 0 replies
 * 1 participant
 * Last reply from: [tau_ceti](https://wordpress.org/support/users/tau_ceti/)
 * Last activity: [19 years, 10 months ago](https://wordpress.org/support/topic/get_posts-isnt-working-right/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
