Skip Navigation

[Résolu] Redirection problem

This support ticket is created Il y a 6 années et 9 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 réponse, has 2 voix.

Last updated by Christian Cox Il y a 6 années et 9 mois.

Assisted by: Christian Cox.

Auteur
Publications
#547870

I added function to redirect user from postype acorrding to advice :
https://toolset.com/forums/topic/how-to-create-post-relationship-between-custom-post-types-2/page/3/

but the problem is it is working on url like this below ( on particular diet created by particular author):

hidden link

but it also redirects user from archive page which presents all diets made by user (parent layout)

hidden link

What to do to redirect all users beside author from particular url of his post but not from archive (but i think archive page is not created by author and thats why the problem persists)

Code below:

function func_custom_redirect() {
	 global $post;
	$post_id = get_the_ID();

$post_type = get_post_type($post_id);
	$current_user = wp_get_current_user();
if(in_array('guest',$current_user->roles) or in_array('author',$current_user->roles) or in_array('customer',$current_user->roles) ){
     if ( "harmonogram" == $post_type || "dieta" == $post_type){
    if(!($post->post_author == $current_user->ID)) {
		
               wp_redirect( home_url('/'));
                 
				die();
        }
	 }
}
}
#547941

Hi, you could use the WordPress is_archive() function to determine whether or not the current page being displayed is an archive page. You can add it to your existing code like this:

if(!($post->post_author == $current_user->ID) && !is_archive()) {
  wp_redirect( home_url('/'));
  die();
}

Please try this and let me know if it works for you.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.