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
- Getting hierarchical custom post type permalinks to work just like pages
- How do I programmatically add items of content to a custom post type?
- List events by month
- Custom Taxonomy archive returns 404
- Adding a span when custom post type is updated
- Pagination with custom post types results in 404 issues
- How do you output custom code between posts in the loop?
- custom post type and custom taxonomy url conflict
- How to make in WordPress admin panel sortable column for the custom field, that count the number of page impressions?
- Output custom post shortcode. Help spot the error.
- Redirecting when changing custom post type slugs?
- Blog page showing same content as homepage
- An empty Custom Post Type Archive page returns 404 in WP 3.1
- A good strategy to print custom posts (offer) that are checked inside the metabox of a post?
- Very Slow Page – How to Optimize # of Queries?
- Custom post type permalink returns bad url
- How to display selected taxonomies by their parent
- Custom Field Order by Last Name and First Name
- Custom taxonomy in URL showing 404
- Custom Post Type Draft Preview Goes to 404
- get the custom post type title/name
- Push metadata in array
- Get custom post type list for every category shortcode
- How do i calculate the total of values of custom fields in custom post types?
- Custom post type – get_day_link()
- 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
- Use custom metabox to update automatically a post after a given date
- get_post_meta not working on publishing
- redirect automatic page that serves custom posttype content
- WordPress custom post type split into pages
- Assign External Database Queries to Global Variables and Make Them Accessible
- Custom post type permalink tag 404
- Custom post type / taxonomy rewrite archive page 2 gives 404
- Different Category system needed for the Custom Post Type
- Specifying Mouseover Icon for Custom Post
- Category.php template for custom posts
- Changed permalink structure of CPT – should I redirect?
- page not found for single-type.php file
- Pagination hitting 404 page on /page/4
- Get data from PHP to JavaScript to set position of each post on front page
- Removing full title and breadcrumb header container for a specific post type
- Query custom post types & Taxonomies and list them in a table on a page
- Creating a “glossary” of WordPress posts of a specific post type
- Using Pagination for Custom Post Type and keeps returning 404
- Nested Custom Taxonomies | Incorrect posts when querying
- Validate Custom Post Type fields
- rewriterule not working
- meta query not retrieving posts
- How do I get the index for a custom post?
- Commas not displaying in implode
- add custom tags for custom post type in wordpress
- CPT Repeatable Fields + Undefined Index
- foreach loop inside the loop creating duplicates in output
- Function to erase every post from a taxonomy
- either single-{custom}.php 404’s OR /taxonomy/ 404’s – custom post type and taxonomy permalinks
- Custom Post Type Causes Error: Warning: call_user_func_array()
- Group episodes by seasons
- Is it a connection or relationship between 2 custom post types?
- Custom front-end form for adding post – Category problem
- Get only parent post in archive post
- update custom taxonomy custom fields
- Filter taxonomy by CPT
- Faking “Same Slug Root, Multiple Custom Post Types” with Redirects?
- Issues with static pages redirecting towards home.php
- Sort custom post column by generated value?
- Action on Custom Post publish
- Remove all feeds and return custom 404 page
- Custom post type order by post_title
- Tell wordpress to show a single page instead of an archive page
- Get meta values from parent post and save in child post
- Some permalinks on Apache/localhost development setup return 404’s when set to anything other than plain permalinks
- PHP Notice: Unidentified index
- Duplicate posts in my custom loop
- How to override post-new.php with custom template
- Include images from pages in wp search.php results in default wp search
- WordPress loop add heading before first of type
- get_post_meta for Custom Post Type ( CPT )
- WordPress query posts by custom post type not workng
- How to display all custom fields associated with a post type – IN THE ADMIN AREA?
- WP_Query return highest number only
- Meta box not saving
- Featured image in custom post is being disabled
- Custom Search not working
- Redirect permalinks after creating custom post types
- Custom Post-type not returning the right child_of
- URL Redirection From Custom Type to Posts
- WordPress Set A Static Page/Template For All Sub-Pages
- Add HTML before a specific div?
- How to hide home title on pages and posts?
- Is there any way of not using my_init_method in the following code (that creates a custom post type)?
- Display ONLY ONE $term (Out of 4 terms) from a Custom Taxonomy and CPT
- Custom post type is_singular condtional not working when managing sidebar display
- Issue displaying multiple TinyMCE editors with WPAlchemy