I have a basic WordPress code that redirects someone to the last post type created on the site, in this case is the "case" post type:
<?php
/*
Template Name: Redirect
*/
$args = array(
'posts_per_page' => '1',
'post_type' => 'case'
);
$post = get_posts($args);
if($post){
$url = get_permalink($post[0]->ID);
wp_redirect( $url, 301 );
exit;
}
I'm trying to expand on this code so I redirect people to their own created posts only, so they will be redirected to the last post they created with an added parameter like ?mode=edit to the end of the url and if they're not logged in, they are going to be sent to a pre-defined error page, like domain.com/error.
I'm a bit new to PHP and for the life of me, I can't figure it out. Any input or hints are appreciated.