Leave a Reply

1 comment

  1. You can use the get_posts() function:

    <?php 
    /*
    Template Name: Redirect
    */
    
    $args = array(
        'posts_per_page' => '1',
        'post_type' => 'post'
    );
    $post = get_posts($args);
    if($post){
        $url = get_permalink($post[0]->ID);
        wp_redirect( $url, 301 ); 
        exit;
    }