homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Display future posts in Wordpress

 9:02 am on Jun 11, 2014 (gmt 0)

I am trying to display future posts in WordPress and have the following code

<?php query_posts('cat=12&posts_per_page=38&orderby=date&order=ASC'); ?>

<?php while ( have_posts() ) : the_post() ?>

<?php //check the dates
$post_date = mysql2date("Ymd", $post->post_date_gmt);
$currentdate = date("Ymd", strtotime('-1 day'));
$expirationdate = $post_date;
if ( $expirationdate > $currentdate ) { ?>

<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>

<?php } //end date check ?>

<?php endwhile; ?>

Which seemed to work well at the beginning but each week I have to change the "posts_per_page" number otherwise posts don't get shown. You'll see I have 38 in the posts_per_page amount but there's only 10 (which is what I want) visible in the site.

I'm presuming it has something to do with the date check code but have no idea what.

Any ideas/help would be really appreciated.



 11:03 am on Jun 12, 2014 (gmt 0)

Your "date check code" is rather cumbersome, but I don't think it's necessarily the cause of your problem.

A potentially inaccuracy with your "date check code" is that $post_date is in UTC time, whereas $currentdate is locale time (less 1 day!). Depending on where you are in the world this could miss (or erroneously include) a few edge cases. The "cumbersome" part is that you are converting the dates to strings (eg. "20140612") and then comparing numerically (PHP is very forgiving), although this should be OK.


 11:16 am on Jun 12, 2014 (gmt 0)

Thanks for the reply.

I know, I'm not a full time coder so generally get bits of other code and cobble something together!

Still no idea why it's not displaying correctly then.


 4:47 pm on Jun 12, 2014 (gmt 0)


Does ASC mean something different in php than it does everywhere else in the world? (This detail would not surprise me.) I'd expect DESC-whatever-they-call-it by default.


 8:23 am on Jul 5, 2014 (gmt 0)

ASC means ascending order.

I have tried using ascending and descending order but I am still unable to get only 10 posts to display.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved