Skip to content

Instantly share code, notes, and snippets.

@wurwal
Created May 2, 2025 09:41
Show Gist options
  • Save wurwal/b03f7129eb61adcff078b0d93f1c77f4 to your computer and use it in GitHub Desktop.
Save wurwal/b03f7129eb61adcff078b0d93f1c77f4 to your computer and use it in GitHub Desktop.
//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