Is there a way that, if a user tries to access a particular page, they are redirected to their most recent post (In a custom post type)?

Or, if the user has no posts, redirect them to the homepage?


To get the permalink of a users most recent post (of custom post type) perform the following query:

$latest = get_posts(array(
        'author' => $current_user->ID,
        'orderby' => 'date',
        'post_type' => 'my_custom_post_type',
        'order' => 'desc',
        'numberposts' => 1,
    if( $latest ) {
      $url = get_permalink($latest[0]->ID);
    } else {
      // No posts

For the redirect part take a look at the function wp_redirect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.