Advertisement
thorbj

display future posts

Jun 29th, 2011
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <ul>
  2. <?php
  3. // Build a custom query to get posts from future dates.
  4. $querystr = "
  5.    SELECT wposts.*
  6.    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
  7.    WHERE wposts.ID = wpostmeta.post_id
  8.     AND wpostmeta.meta_key = 'Dato'
  9. AND STR_TO_DATE(wpostmeta.meta_value,'%d/%m/%Y') >= CURDATE()
  10.  
  11. AND wposts.post_status = 'publish'
  12. AND wposts.post_type = 'post'
  13. ORDER BY STR_TO_DATE(wpostmeta.meta_value,'%d/%m/%Y') ASC
  14. LIMIT 3
  15. ";
  16.  
  17. $events = $wpdb->get_results($querystr, OBJECT);
  18.  
  19.  if ($events):
  20.     foreach ($events as $post):
  21.         global $post;
  22.         setup_postdata($post); ?>      
  23.             <li>
  24.             <?php the_meta(Dato); ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  25.             </li>
  26.     <?php endforeach;
  27. else : ?>
  28.     <li>Can't find any posts...</li>
  29. <?php endif; ?>
  30. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement