How do I get Link for Oldest Custom Post Type (dynamically)

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

Related posts

Leave a Reply

1 comment

  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>