Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

At first I thought the task was trivial. I'd like to list the most recently added posts (say, 15 of them), but I am adding posts that are dated a few years back, yet I'd like them to show in the list, instead of just the ones that are dated the most recent.

This is what I'm doing so far:

<?php
    $args = array( 'orderby' => 'modified', 'numberposts' => 15 );
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post);

        $audio = get_children(
            array(
                'post_parent' => $post->ID,
                'post_status' => 'inherit',
                'post_type' => 'attachment',
                'post_mime_type' => 'audio'
            )
        );
        $thishref = "";
        foreach ( $audio as $attachment_id => $attachment ) : 
            $thishref.= wp_get_attachment_url( $attachment_id, 'full' );
        endforeach;
?> 
<li>
    <a href="<?php the_permalink(); ?>"><?php the_title();?></a>&nbsp;
    <span title="comments" class="commentCount">(<?php comments_number( '0', '1', '%' ); ?>)</span>&nbsp;&nbsp;
    <a title="download" class="downloadlink" href="<?php echo $thishref; ?>">&darr;</a>
</li>
<?php
    endforeach;
?>

It works, except if I add tags to a post or edit it in any way, the post becomes 'modified' and thus appears in this list, and I'd like to prevent this from happening.

In other words, I want to list 15 most recent posts not by their date, not by their modified date, but by the date they were added to the database of posts ('created' date?).

Would this be at all possible?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Try:

$postslist = get_posts( 'orderby=ID&numberposts=15' );

Here, we're ordering by the ID, which should relate to when the posts were added to the database.

share|improve this answer
    
Thank you very much! Simple and elegant solution. –  pereyra Feb 19 '13 at 15:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.