Publish Specified Number of Posts in Ascending Order

Handy when listing date / event oriented posts on a feed. Sourced here.

$myposts = get_posts('cat=3&showposts=20');
if ($myposts) {
  foreach ($myposts as $mypost) {
      'post__in' => $uc,
      'orderby' => 'post_date',
      'order' => 'ASC',
      'posts_per_page' => 20,
      'caller_get_posts' => 1
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'Category 3, lastest posts, sorted oldest to newest';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><small><?php the_time('m.d.y') ?> </small><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    } //if ($my_query)
  wp_reset_query();  // Restore global post data stomped by the_post().


Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.