It looks like template_redirect
is as far up the WordPress action chain you can go while still being able to detect that a 404 error is being thrown. This action will trigger before any template files would be loaded so it will happen before loading unnecessary resources.
You can try adding this into your /wp-content/themes/yourtheme/functions.php
file to achieve a dynamic redirect for all 404’s that happen when viewing single jobs:
add_action( 'template_redirect', 'unlisted_jobs_redirect' );
function unlisted_jobs_redirect()
{
// check if is a 404 error, and it's on your jobs custom post type
if( is_404() && is_singular('your-job-custom-post-type') )
{
// then redirect to yourdomain.com/jobs/
wp_redirect( home_url( '/jobs/' ) );
exit();
}
}
Related Posts:
- Custom 404 redirect for a luddite
- Inconsistent temporary 404s on whole install | PHP error with post-template.php
- How to redirect all pages of a custom post type [duplicate]
- Custom Post Type without an archive page
- Redirect 404 page with ID in slug to associated page with same ID in slug
- Create short URL with auto 301 redirect
- redirect after submiting post for review
- WP_Query is printing out only one post when posts_per_page is set to multiple
- WP Query to displaying date and posts for that date?
- GravityForm: Populate Dropdown with custom post type [closed]
- Return array of categories to php function for current post
- Link users to a custom post type
- Create a random unique 6 digit number as custom field for custom post type
- How to output wordpress custom tags separated by comma?
- Loading all files within a directory
- Different permalink for CPT and regular Posts/Pages but why?
- Blog page showing same content as homepage
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- An empty Custom Post Type Archive page returns 404 in WP 3.1
- Using several custom fields as custom post title
- Get rewrite slug of custom post type in template
- Show Different Header on a Specific Post ID
- Get Post Primary Category
- Weird problem happening with custom taxonmy when creating/updating posts
- A good strategy to print custom posts (offer) that are checked inside the metabox of a post?
- How To Create A Custom Taxonomy 404 Page
- Admin notice not displaying
- Can’t get order_by meta_value_num to work properly
- Custom Post Type + 20k posts = blank/404 within Admin edit.php [duplicate]
- Create custom post type on successful woocommerce order [closed]
- Adding custom tables to WordPress
- Delete link on single-custom.php with redirection
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- Redirect page to first post in custom post type
- Custom Taxonomy Permalinks Redirection
- Bizarre Permalinks Issue: 404 Errors Everywhere
- Very Slow Page – How to Optimize # of Queries?
- Dynamic page outside WordPress
- Create/Edit posts and auto-redirect back to listing page
- Using wordpress template tags within an array
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- Getting the URL of the parent page
- Custom query to filter posts that have current post as a taxonomy [closed]
- Custom post type permalink returns bad url
- Return the thumbnail meta data for getter and setter
- How to display selected taxonomies by their parent
- Custom Field Order by Last Name and First Name
- Pagination for custom php code
- get_posts of Custom Post Type AND Custom Taxonomy
- WordPress does not load page.php, return 404.php
- What’s the difference between same wp functions get_posts(); functions in different form?
- Custom taxonomy in URL showing 404
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- Custom Post Type Draft Preview Goes to 404
- Custom Post Type Loop throws 500 error when used in widget
- how to check if custom post type column already exists?
- Get posts from a custom post type by child categories of a parent category
- Received nothing after executing AJAX post function
- How to make sure content doesn’t display if selection is empty
- Custom post type redirected to homepage – how to debug
- Custom Post-Type not in admin menu
- get the custom post type title/name
- Page vs Custom Post Types Differences/Issues
- If post has custom field then display css-class
- Push metadata in array
- How to customize a permalink (URL) structure?
- Troubles with saving metabox
- Custom Post Type / Two level deep taxonomy (cat. and subcat.) uri problem (error 404)
- CPT + CMB2: data not displaying for only first post in loop
- How to make a field appear only if a post meta field has a defined value?
- Replace text in post from cvs
- Get parent categories of custom post type
- Wrong request query on cpt and tax
- Can I list a custom post type within another custom post type in the admin area?
- Get custom post type list for every category shortcode
- How do i calculate the total of values of custom fields in custom post types?
- I would like to have different styles for my posts based on the content of each post
- Checking if Post Title is Unique as Loop Criteria
- 301 redirect for converted post type
- redirecting improperly after updating custom taxonomy term when referring from CPT edit page
- Query & Order posts by custom fields
- How do I display content to users who are not logged in instead of 404 on Private custom posts?
- Custom post type – get_day_link()
- Set URL link to featured image of custom post type
- Child post with numeric only slug keeps redirecting to parent
- Custom Tag Description unable to display just below and outside of the Loop
- AJAX load more for different custom post type loops
- Help with Elementor Pagination CPT archive 404 problem
- WP_Query to select custom post type with Advanced Custom Fields (ACF) date
- On update or create post redirect to current post position in list
- I need to add endpoint for wordpress categories
- I’d like to cycle through existing posts in a post type, showing one per day ordered by title, and starting over when the last is reached
- 404 error when navigating to a taxonomy page with Cyrillic, what’s wrong?
- Changing wordpress publication date to ACF date and time picker date not working
- Trouble with CPT Child 404
- Why are taxonomy terms not saving when using custom meta boxes with radio button taxonomy selectors?
- Use custom metabox to update automatically a post after a given date
- get_post_meta not working on publishing
- creat filter with wp_query
- WordPress wrapped added a span tag to every single p tag