Title: wp_get_recent_posts
Last modified: August 21, 2016

---

# wp_get_recent_posts

 *  [aliwebdesarrollo](https://wordpress.org/support/users/aliwebdesarrollo/)
 * (@aliwebdesarrollo)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/wp_get_recent_posts-1/)
 * Hi there, i’m making my own theme and i have a little problem with one function.
 * I just want to show the last 5 post (publish post), without taking in count the
   category. So when the visitor goes to a category at the sidebar could see the
   last X (could be 5 or 10) last post published.
 * To make that i’m using the function **wp_get_recent_posts** but there is a problem
   apparently because doesnt work. It crash when try to load the file sidebar.php
   with that function. And i know that the problem is wp_get_recent_posts because
   if i use a loop with query_post works fine (but i dont want to use this function!).
 * I paste here the code, its almost the same that it s in the Codex page.
 *     ```
       <ul id="LastPostList">
       <?php
       $args = array(
           'numberposts' => 5,
           'orderby' => 'post_date',
           'order' => 'DESC',
           'post_type' => 'post',
           'post_status' => 'publish',
           'suppress_filters' => true );
   
           $recent_posts = wp_get_recent_posts( $args, $output = ARRAY_A );
           foreach ($recent_posts as $recent)
           {
           	?>
       	<li class="LastPost"><a href="<?php get_permalink({$recent['ID']}) ?>" title="<?php esc_attr({$recent['post_title']})?>" ><?=$recent["post_title"]?></a></li>
           	<?php
           }
       ?>
   
       </ul>
       ```
   
 * Maybe there is something that i cant see… i also try to enable the debug option
   but didnt shows anything, and the server error file nether.

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

 *  [graphical_force](https://wordpress.org/support/users/graphical_force/)
 * (@graphical_force)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/wp_get_recent_posts-1/#post-4039142)
 * Have you looked at WP Query? [http://codex.wordpress.org/Class_Reference/WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query)
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/wp_get_recent_posts-1/#post-4039201)
 * caused by the curly brackets you have in your code which are not in the Codex
   examples;
 * change the one line to:
 *     ```
       <li class="LastPost"><a href="<?php get_permalink($recent['ID']) ?>" title="<?php echo esc_attr($recent['post_title']); ?>" ><?php echo $recent['post_title']; ?></a></li>
       ```
   
 * to get error messages while developing your site, consider to enable DEBUG [http://codex.wordpress.org/Debugging_in_WordPress](http://codex.wordpress.org/Debugging_in_WordPress)

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

The topic ‘wp_get_recent_posts’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/wp_get_recent_posts-1/#post-4039201)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
