You can use an earlier action, request
, to do whatever you need. It allows you to modify query variables, or even cancel the entire request without issuing a 404 error:
function wpse112929_cancel_request_parsing( $query_vars ) {
if ( in_array( 'pagethatdontexist', $query_vars ) ) {
return array();
}
return $query_vars;
}
add_action( 'request', 'wpse112929_cancel_request_parsing' );
I used in_array()
here instead of a direct comparison, because
the actual match
depends on your permalink structure.
It would be name
for /%postname%/
, category_name
for /%category%/%postname%/
, pagename
for /%year%/%monthnum%/%postname%/
, etc.
You can also check $_SERVER['REQUEST_URI']
instead.
Related Posts:
- Why is the loop not empty on some 404s?
- How to stop wordpress to make the default query?
- Query two taxonomies via URL or link?
- How to trigger 404 for custom query var?
- Pagination shows 404 after a certain number of pages
- Multiple endpoints in one URL
- Pagination causes error 404 when used with front-page.php
- WP-PageNavi gives me a 404 when using WP Query
- Can not switch the queried post in pre_get_posts hook
- Is there a PHP function that can match anything after the given URL, so my IF statement will work in each instance?
- Intentionally exceed max_num_pages on main query without getting 404?
- Get rewrite result
- Difficulty with rewrite rules
- Custom pagination with WP_Query generating 404 error
- if/else on custom query gives 200 OK when condition not met?
- Have functions work outside the loop with 404 override
- remove query arg from url after set query
- WordPress add_rewrite_rule() cannot visit lower url levels
- Serve specific “template” page at any URL that ends in its slug
- How to figure out redirection and contents in hybrid solution containing word press content and legacy code (ASP.net)
- How to return a 404 when custom query matches nothing?
- paged variable not working for category/custom post archive
- Issue with front page navigation after upgrading to 3.4
- Show a 404 error page if Public query variable’s value doesn’t exist?
- is_404() – where does this get set?
- Custom Taxonomy Breaks Pages
- Reciving Error 404 blog/page/2/
- WordPress rewrite with custom parameter doesn’t work
- Show a message if there are no active posts in category
- How to allow a variable with “/” in wordpress url
- How can I re-query post_type and rewrite the url?
- Rewrite rule pagination on different url levels
- How to list posts of a given format
- Pagination with Custom Post Type not working on index.php: I get a 404
- Pagination on custom post type not working
- taxonomy-{term}.php terms pagination returning 404 after a certain page
- How can i retrieve default post per page value? from settings->reading. And total number of posts?
- Exclude Child Posts from WP_Query
- WP_Query for WooCommerce Products
- WP_Query with two post types, but requiring category on only one of those post types
- How to limit the posts
- How to order posts in wp_query by a meta_value of the corresponding author
- How to get sum of meta_values of a meta_key in wp_query according to conditions
- Get the post thumbnail with wp_query
- Where to use $post global variable?
- Multiple instances of Featured Image Query
- Categories not working – 404 Not found error
- WPDB query – decrypting DB data
- Storing query variable and then using wp_reset_query
- exclude posts with a specific custom field and value
- Redirect page when URL parameter not set
- WordPress Pagination changes my template
- wp_query ignoring custom post_status
- Query posts(CPT, pages , hierarchical) by Ancestor ID
- Input check to custom post type query
- Get a list of posts with associated meta_value
- Show all data in database table and make it into an interactive table
- How to filter a query by date in a shortcode?
- Query post with meta value in set of values
- How to querry for an item that saved in an array?
- get_post() is not returning correct value
- CPT category post/content is not showing on my page, Please review my coede
- Advise on Templates for Custom Queries
- Creating a query that get all posts but places meta items first
- How to wp_query every Sunday between a startdate and enddate?
- Why last row deleted when refresh page
- wp_query with meta_query and tax_query
- WordPress live search and filter custom fields
- Avoid removing duplicate posts
- Get post Number with local loop and template
- WP_Query tax_query only returning posts that match first term
- Get post related to current post
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- Featured Image as Background with Offset
- custom WP_Query results in showing same posts in all pagination pages
- Show recent posts from excluded category
- List posts of terms but exclude one term
- Passing query variables to a custom page template
- Query child’s child categories
- $wp_query issue when trying to create a virtual page
- add_query_vars does not work
- Retrieve posts in custom post type and specific taxonomies
- Get users query makes the site loading time too big?
- Get posts that were most recently tagged
- WordPress extremely slow when using get_posts with multiple meta_query relations
- Refresh wp_query with no changes
- SQL query into to WP query
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- I want to place a post before all others from an ACF boleen field
- Search results stuck on page 1
- How to put posts with some taxonomy on top of others in `pre_get_posts`
- wp_query, calculate with two dates when ‘key’ is text format
- Use value from meta key array for use in WP_Query
- WP_Query sort by ACF date field (newest first) with blank dates first
- Post pages are redirecting to the 404 page in wordpress
- Pagination only showed when no category is set in wp_query
- Using WP Query, I want to include all posts in category 1 as long as they are not also in category 2
- Prevent URL Parameter Affecting other WP Query
- Sort by multiple columns using get_posts
- WP_Query filter Posts by timestamp event (range start and end) and by month (next 12 month)