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
- Broken? WP_Query and “attachment” as a post type
- Order by DESC, ASC in custom WP_Query
- Exclude or Include category ids in WP_Query
- Secondary Sort (fallback) for WP_Query
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query Posts in a Predefined Order
- Use WP_Query with a custom SQL query
- How to make an activities stream mixing posts and comments?
- WP_Query based on URL parameters
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- How to query for a week using key => value WP_Query argument notation?
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- Order posts ascending with number in title
- How can I style future post?
- List taxonomy terms plus their latest post ordered by post date
- WordPress altering my custom query, How to fix it?
- Looping through tabular data
- Using next/previous_posts_link with customised search
- using wp_query to return posts w/ comment count > 0
- Order by meta_key in custom post type doesn’t affect the query
- How to create/modfiy WP_Query to search in post title OR custom field?
- Add a default meta_value to new posts
- How to detect custom query inside `posts_where` hook?
- Is temporarily overwriting $wp_query a bad idea?
- Array Chunks and Inserting Varying HTML in WP_Query
- WP query exclude post within the last month / only show over 1 month old
- WordPress query for most recent posts from multiple categories
- Too many posts cause slow load when paginating
- How to output different posts per page?
- Order Posts by meta value AND published date
- Pass array of taxonomy terms to wp_query
- Modifying the Search Results
- WP_Query times out
- Offset Page Loops and Pagination
- How to find a post id using the post_excerpt?
- wp_query add arguments using array_push if variable met
- Comparing dates in custom field
- reducing the amount of wp_query calls
- WP_Query filter and order by meta ordering by wrong joined table
- List of the years with posts presented
- Query custom post type by custom taxonomy (category slug)
- Querying A Post That Includes Two Taxonomies Using JSON Rest API
- WP_Query condition affects posts_per_page count
- Advanced Taxonomy Queries WordPress
- Use post object from first query in second query
- Order by title without taking into account ‘the’
- Getting post revision and printing them on the post content site
- Editing the default wordpress search
- Slow page loads due to WordPress Core Query
- Set global $wp_query/$post variable for dynamic page generation
- wp_query for multiple cities (multiple values in a metabox)
- Adding column to wp_posts table or join wp_posts table with another table
- slow WP_Query for non-admin user
- get posts by meta_key from inside key of post meta
- Help optimizing slow WP_Query with meta_query
- meta_value_num not ordering all items
- Meta Queries – should nesting work after WP 4.1?
- Use meta query only 3 or more results?
- How to prevent WP query searching in executed shortcodes
- WordPress – Optimize the Meta Query for 3 meta keys at a time
- posts_per_page showing 16 elements instead of 3
- WP_Query filtering in ACF field containing dates
- Conditionaly move certain posts at the bottom of the query result
- How to `’orderby’ => ‘meta_value_num’` in a series of orderby parameters