Welcome to WebmasterWorld Guest from 54.162.155.183

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Display future posts in Wordpress

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

5+ Year Member



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 ) { ?>

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

<?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)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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)

5+ Year Member



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)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



&orderby=date&order=ASC

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)

5+ Year Member



ASC means ascending order.

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

Featured Threads

Hot Threads This Week

Hot Threads This Month