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.

Anyone know how I could take the below script that was answered for retrieving the latest permalink for a Custom Post Type and flip it to get the oldest post instead?

This is the link for retrieving custom post type latest post

share|improve this question

1 Answer 1

Simply change order parameter from DESC to ASC:

function Get_First_permalink(){
    global $post;
    $tmp_post = $post;
    $args = array(
        'numberposts'     => 1,
        'offset'          => 0,
        'orderby'         => 'post_date',
        'order'           => 'ASC',
        'post_type'       => 'POST_TYPE_NAME',
        'post_status'     => 'publish' );
    $myposts = get_posts( $args );
    setup_postdata($myposts[0]);
    $permalink = get_permalink($post->ID);
    $post = $tmp_post;
    return $permalink;
}

so once you paste that function in your theme's functions.php and you have changed POST_TYPE_NAME to your post type name ,you can just call it whenever you want:

<a href="<?php echo Get_First_permalink(); ?>">First Post</a>
share|improve this answer

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.