Created
May 2, 2025 09:41
-
-
Save wurwal/b03f7129eb61adcff078b0d93f1c77f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//REDIRECTS DRAFTED WHATS ON POSTS TO BASE CATEGORY PAGE | |
add_action('template_redirect', 'redirect_draft_post_in_category'); | |
function redirect_draft_post_in_category() { | |
if (is_singular('post')) { | |
global $post; | |
// Check if the post is a draft | |
if ($post->post_status === 'draft') { | |
// Replace 'my-category-slug' with your actual category slug | |
if (has_category('whats-on', $post)) { | |
// Replace with your target URL | |
wp_redirect(home_url('/category/whats-on/')); | |
exit; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment