Skip Navigation

[Resolved] Conditional Redirect to Homepage if Current User ID is NE to Post Autor ID

This support ticket is created 3 years, 1 month ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Adrian Robbins 3 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#2206127

We are developing a booking itinerary system, where a client can view a single post of their booking for the coming year. Each client will only ever have ONE custom post that they own.

We would like to create a 'conditional' redirect to the Home Page, in the event that a client manually changes their booking URL in an attempt to view someone elses booking - our booking references are sequentially numbered.

So, URL hidden link displays the clients booking, because they are logged in as user 221234

However if they change to this URL, hidden link I would like them to be redirected back to the home page

hidden link

We found this code:

function tssupp_redirect() {

if ( !is_user_logged_in() && is_page('inaccessible') ) {
wp_redirect(home_url());
exit;
}

}
add_action('template_redirect', 'tssupp_redirect');

However it is not redirecting in the way we want

Can you please help?

Kind regards
Ade

#2206753

Hello,

How do you setup the relationship between "client" and "booking"?
"booking" post author is each "client" user?

Please provide more details for the questions.

#2206947

Hi Luo

We have managed to sort the problem as follows:

<!-- wp:html -->
[wpv-conditional if=" ( ( '[wpv-current-user info='id']' ne '[wpv-post-author format='meta' meta='ID' ]' ) ) "]
<!-- /wp:html -->

<!-- wp:html -->
<div class="jump" id="details">
<p>You can only view your own booking for this years Open.</p></div>
<!-- /wp:html -->

<!-- wp:html -->
[/wpv-conditional]
<!-- /wp:html -->

<!-- wp:html -->
[wpv-conditional if=" ( ( '[wpv-current-user info='id']' eq '[wpv-post-author format='meta' meta='ID' ]' ) ) "]
<!-- /wp:html -->

Kind regards
Ade

#2206955

My issue is resolved now. Thank you!