The function you are using– post_password_required— is true for password protected pages, not for private pages. I am honestly not sure which you mean, but if you do mean “private” as in most of your description then…
I am not aware of an is_private function but you can check the post object itself. There is a catch though. “Private” posts are rabidly protected. A user without permissions to see the post will get a 404. I think the following will work, but due to the nature of “private” posts this may still be buggy. It has not been rigidly tested.
function redirect_to_login() {
global $wp_query,$wpdb;
if (is_404()) {
$private = $wpdb->get_row($wp_query->request);
if( 'private' == $private->post_status ) {
wp_safe_redirect(home_url(get_permalink(188)));
die;
}
}
}
add_action('template_redirect', 'redirect_to_login');
Related Posts:
- Correct method of redirecting user login
- Editing ‘Password Reset’ E-mail
- Change “You are now logged out” text
- Removing labels and tag on WordPress’s default login form
- Customize user account activation message
- How do we check if the user is logging in or registering?
- add filter login_redirect does not contain original requested redirect
- Change username before login
- Custom Login Errors and variables I can use
- Filters on Login Page
- How can I change the email that is inside the default email texts of wordpress?
- How do I hook my function to run only after submitting login form
- Change login CSS
- Filter wp_redirect() to stop redirect under certain condition
- Filter page title (displayed in browser tab) of wp-login
- How to redirect a unique link based on login status
- login_url filter creates permanent wp-admin -> wp-login redirection loop
- Login logout below menu bar
- Hook into ‘when user logs in’ [persistent login]
- Change password reqts with NO plugin without breaking resetpass link?
- Changing WooCommerce Display Price Based on User Role & Category [closed]
- Remove Editor From Homepage
- What do add_filters() and apply_filter() do?
- Password change when the user login first time
- What to use instead of the content_save_pre filter?
- How can I customize the wp_list_categories
- How can I reliably and globally disable wptexturize?
- Customise Jetpack Publicize text
- Can’t change a label in woocommerce with the normal filter
- Add classname to the_category() function?
- Filter the URL of next_posts_link & previous_posts_link
- Sensei LMS Hooks to Remove Content
- How to re-enable a filter after disabling with __return_false
- redirect pages with no content, instead of 404 error, using max_num_posts?
- Exclude One Category and its Subcategories using WP_LIST_FILTER
- Explanation for remove_filter used in the below code [closed]
- How to change the blog title with add_filter? details below
- Gutenberg disable the “block” tab in right sidebar
- When to use actions and when to use filters
- add_filter to ‘woocommerce_before_main_content’ [closed]
- Editing
- the_content filter – checking the post
- add_filter to apply_filters that exists within class
- Echoing Categories only if they’re a child of a given category
- Removal of Jetpack OG Tags from old blog site
- Adding a title prefix with the the_title filter
- How to removes all instances of thumbnails displayed in my theme?
- How to modify an existing meta description?
- Adding TinyMCE buttons without removing plugin buttons?
- Don’t see add_filter result in the site front page
- How can I include an existing custom sitemaps listing in wp-sitemap.xml?
- Display Externally Retrieved Data within a Custom Template
- Can the wordpress color palettes by changed through Javascript?
- Filter on the_content doesn’t update the content being searched via register_rest_route
- Where to add_filter in theme functions.php?
- tag removed not using a filter
- Give “Read More” precedence over excerpt() word count
- Adding a filter to comments_template
- How to customize category_description()?
- Add Bootstrap Classes to Recent Posts Widget
- Add filter to get_posts
- How can I output all apply_filters and do_action?
- Override has_post_thumbnail function
- Is it possible to override the default Gallery Settings form?
- Excerpt is being added above the content, but it should be after it
- WordPress add script with custom type (x-jquery-tmpl)
- Woocomemrce order and registration fileds to UPPERCASE
- How to combine multiple body classes
- How to replace username with email address in users table
- why require – does not load filter
- term_link filter rewrite link only applying half of condition?
- How to change dynamically page title according to variable data?
- How can I filter tag_description()?
- What is the action hook to use if you want to capture the new password during password change?
- Get_template_part inside filter?
- Need to return shortcode text instead of the output
- Dashboard filter based on custom fields URL response code
- I want to add string array to this function to filter displayed option in drpodown [closed]
- Remove style tags from head
- How to wrap pattern-matches from the_content in [wiki]-shortcode tags
- how to develop a filter in wordpress to let the user filter the page content depends on the date (newest to oldest etc…)?
- Print only parent categories of post in custom RSS feed
- Redirecting the lost password page request when using a custon login page
- Use add_filter inside another function
- How to filter reading/visibility posts based on role?
- Admin view: filter posts by whether they have specific taxonomy attached
- Filter posts by categories ajax is showing all the posts
- Incrementing content with extra text after save/publish
- Filter and validate user role in registration
- How to use a TinyMCE filter?
- Unable to get WordPress’s apply_filters(‘site_url’) to return a https scheme
- String Replace Caching & Chance of Collisions
- Admin filter/error if post title is too long
- What is the scope and persistence of add_filter() and remove_filter()?
- GET form action. Redirect to self
- After adding filter to plugin’s code, post’s content doesn’t display
- if i put the code in my theme’s function.php file can it work?
- Admin New Order: Autofocus on Search a product
- Is it possible to dynamically change the “page_for_posts” option?
- Why is the change in my query not taking into account