0

Simply I have made a custom post type named ticket and have created an archive-ticket.php file I want to make if the user that tries to visit the tickets archive page is not administrator redirect him/her to the home page.

I can make a simple solution like add something like this code in the file direct:

wp_redirect( home_url( '/' ) );
exit();

Buy i feel that this is not a profestional solution and feel that this is bad for seo.

2
  • Hi. What is your question then? – Howard E Feb 25 '20 at 10:46
  • @HowardE What's the best solution to achieve what i need, Using the wp_redirect( home_url( '/' ) ); direct in the archive file is correct and not a poor solution or not? – John Feb 25 '20 at 11:04
-1

can you add this code in your archive-ticket.php before get_header().
please check below snap for the same.

enter image description here

$user         = wp_get_current_user();
$roles        = (array) $user->roles;
$current_role = $roles[0];
$allowed_role = array('administrator');
if (!is_user_logged_in() || !in_array($current_role, $allowed_role)) {
    wp_redirect(site_url());
}

Thanks.

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.