Redirecting Based on User ID(s) in Post Meta

This Pro tutorial provides the steps to redirect single post pages to a specific URL/location like the site's homepage if the user viewing the page is not the one set as the value of a custom field for that post.

Sample scenario:

CPT: service

Custom Field: access_user of the type User created using a plugin like ACF or Meta Box.

For a service titled say, "SEO" this custom field's value has been set to "John Smith".

When example.com/service/seo/ is viewed by anyone but John Smith, we shall redirect them to the homepage.

We are also going to cover the case where the custom field can contain multiple users.

Add the following in child theme's functions.php or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Instant access to all 250+ Bricks code tutorials with BricksLabs Pro