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="https://wordpress.stackexchange.com/questions/18647/<?php echo Get_First_permalink(); ?>">First Post</a>