Title: Latests posts shows future posts Problem
Last modified: August 18, 2016

---

# Latests posts shows future posts Problem

 *  [phoenixd](https://wordpress.org/support/users/phoenixd/)
 * (@phoenixd)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/latests-posts-shows-future-posts-problem/)
 * I am sure someone fixed this before, I just need to know what to change this 
   code to in my my-hacks.php file.
 * `
    function get_recent_posts($no_posts = 5, $before = '
    - ', $after = '
    - ', $show_pass_post = false, $skip_posts = 0) {
       global $wpdb, $tableposts;
      $request = "SELECT ID, post_title FROM $tableposts WHERE post_status = 'publish'&";
      if(!$show_pass_post) { $request .= "AND post_password ='' "; } $request .="
      ORDER BY post_date DESC LIMIT $skip_posts, $no_posts"; $posts = $wpdb->get_results(
      $request); $output = ''; foreach ($posts as $post) { $post_title = stripslashes(
      $post->post_title); $permalink = get_permalink($post->ID); $output .= $before.'
      [' . $post_title . '](https://wordpress.org/support/topic/latests-posts-shows-future-posts-problem/&apos; . $permalink . &apos;?output_format=md)'.
      $after; } echo $output; }

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

 *  Thread Starter [phoenixd](https://wordpress.org/support/users/phoenixd/)
 * (@phoenixd)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/latests-posts-shows-future-posts-problem/#post-320061)
 * I don’t want to have to do an ugly date and time comparison… :$
 *  Thread Starter [phoenixd](https://wordpress.org/support/users/phoenixd/)
 * (@phoenixd)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/latests-posts-shows-future-posts-problem/#post-320065)
 * I did the ugly date comparison. I guess its the only way to do it, and it works.
   🙂
 * function get_recent_posts($no_posts = 5, $before = ‘
    - ‘, $after = ‘
    - ‘, $show_pass_post = false, $skip_posts = 0) {
       global $wpdb, $tableposts;
      $today = date(“Y-m-d H:i:s”);
    -  $request = “SELECT ID, post_title FROM $tableposts WHERE post_status = ‘publish’
      AND post_date < ‘$today’ “;
       if(!$show_pass_post) { $request .= “AND post_password
      =” “; } $request .= “ORDER BY post_date DESC LIMIT $skip_posts, $no_posts”;
      $posts = $wpdb->get_results($request); $output = ”; foreach ($posts as $post){
      $post_title = stripslashes($post->post_title); $permalink = get_permalink(
      $post->ID); $output .= $before . ‘[‘ . $post_title . ‘](https://wordpress.org/support/topic/latests-posts-shows-future-posts-problem/&apos; . $permalink . &apos;?output_format=md)‘.
      $after; } echo $output; }

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

The topic ‘Latests posts shows future posts Problem’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [phoenixd](https://wordpress.org/support/users/phoenixd/)
 * Last activity: [20 years, 4 months ago](https://wordpress.org/support/topic/latests-posts-shows-future-posts-problem/#post-320065)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
