WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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 );
    $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


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.