The timing of relevant parts of the process is following:
- Query executes and fetches posts (or in this case no posts)
template_redirect
fires- Template file is determined from query variables and loaded
When you change query variables in template_redirect
you change template choice (which you observe), but you still have no posts in query.
The functions still work, they just don’t have a post to work on.
It’s quite a peculiar case, because which posts would you expect in an archive that is 404 and has no posts?
I am not sure without playing with such a setup but I would probably try to redirect “ahead” rather than “fake” valid page out of 404.
Related Posts:
- How to prevent random 302 canonical-ish redirect on custom template
- Page template query with WP_Query
- Wp_redirect and sending variables
- Why is the loop not empty on some 404s?
- How to prevent execution of default query, while preserving ability to use WP_Query in template?
- How to stop wordpress to make the default query?
- $wp_query initiation?
- Executing Queries in tag.php
- How to trigger 404 for custom query var?
- Pagination shows 404 after a certain number of pages
- Pagination causes error 404 when used with front-page.php
- Which custom query am I in and how can I access its properties & methods?
- Single page theme
- WP-PageNavi gives me a 404 when using WP Query
- Intentionally exceed max_num_pages on main query without getting 404?
- Pass the same object to multiple widgets in a template with one query
- Custom pagination with WP_Query generating 404 error
- if/else on custom query gives 200 OK when condition not met?
- Show all post for a given category
- add_filter(‘query_vars’) not working in custom template
- How to return a 404 when custom query matches nothing?
- paged variable not working for category/custom post archive
- Is there a better way to pull in custom content without querying posts?
- Issue with front page navigation after upgrading to 3.4
- Show a 404 error page if Public query variable’s value doesn’t exist?
- WordPress Custom Search Form Displaying Unexpected Results
- How to use if($wp_query->query_vars[‘name’] == ‘pagethatdontexist’) without getting a 404? How to suppress 404
- Is there a way to make this kind of loop shorter and nicer?
- Utilising an existing page while using the “s” query parameter
- Get posts in taxonomy randomly
- How to generate feed for custom template
- is_404() – where does this get set?
- Custom Taxonomy Breaks Pages
- Unable to paginate a custom page query
- How to stack name list in non-alphabetical order?
- problem with the loop
- get_children() Archive Template
- Reciving Error 404 blog/page/2/
- In a WP_Query can I force the results’ is_singular() to be set to false?
- Show a message if there are no active posts in category
- How to display a post(by id) along with css in a page?
- Display a custom 404 page without a redirect
- ACF: using two loops, the_field returns field content from another loop
- Search Filter With Custom Taxonomy and Custom Fields : How do I handle it via plugin?
- How to redirect a query string to a “virtual” subdirectory
- WordPress Prevent 404 on missing custom post
- Passing query variables to a custom page template
- Adding css tweak based on page template
- Pagination with Custom Post Type not working on index.php: I get a 404
- on attachment.php, how to display previous and next attachment links that follow the same order as a custom WP Query
- taxonomy-{term}.php terms pagination returning 404 after a certain page
- How WP determines archive page vs single page?
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- WP_Query by just the id?
- Meta_query compare operator explanation
- WP_Query with “post_title LIKE ‘something%'”?
- wp query to get child pages of current page
- How to get an array of post data from wp_query result?
- How to force a 404 on WordPress
- How to get post id of static front page?
- meta_query with meta values as serialize arrays
- How to only display posts whose meta_value field is not empty?
- Get post ids from WP_Query?
- Pagination when using wp_query?
- Exclude post ID from wp_query
- How to print the excuted sql right after its execution
- How to extend WP_Query to include custom table in query?
- How to store and receive variables in WP sessions?
- Should I use Pre Get Posts or WP_Query
- How can i retrieve default post per page value? from settings->reading. And total number of posts?
- Nested meta_query with multiple relation keys
- Is it necessary to use wp_reset_query() in a WP_Query call?
- Can I force WP_Query to return no results?
- Can wp_query return posts meta in a single request?
- Using pre_get_posts with WP_Query
- Redirect Restricted Page to 404
- Find out total number of pages in global query on archive page?
- WP_Query + random
- Resetting post data to previous loop in nested loops
- order by numeric value for meta value
- numberposts? showposts? posts_per_page?
- $GLOBALS[‘wp_the_query’] vs global $wp_query
- Broken? WP_Query and “attachment” as a post type
- Some doubts about how the main query and the custom query works in this custom theme?
- Order by multiple meta key and meta value [closed]
- Post_count only shows the number of results per page
- How to prevent automatic redirection of 404 errors and “incorrect” URLs?
- How do I skip wordpress’s 404 handling and redirect all 404 errors for static files to 404.html?
- meta_query ‘compare’ => ‘IN’ not working
- Query posts only with featured image
- Wp get all the sub pages of the parent using wp query
- What is appropriate flow for custom data from URL in WP_Query?
- How to display page content in a page template?
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- How to merge two queries together
- Posts with at least 3 tags of a list of tags
- Get post count of current loop when using multiple queries on one page
- why ignore_sticky_posts in sticky post query
- Multiple relationship for multiple tax_query in WP_Query