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:
- 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
- meta_query ‘compare’ => ‘IN’ not working
- Sorting: custom query with orderby meta_value_num THEN by title
- WP_Query and next_posts_link
- replace the WP_Query class in the main query
- Get posts with condition on comment meta value
- WP_Query sort by comment meta data
- WP_query ‘orderby=none’ Problem
- How do I redirect all 404 errors of a specific post type to another URL?
- Display different number of posts from one category on the different pages
- How to display child posts in the parent category
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- Order terms inside a select dropdown
- Ordering by meta_value AND date NOT WORKING with wp_query
- Transient caching for wp query
- Custom WP Query from meta_value stored as serialised array
- Get List of all the Authors
- How to check if a post “does not have term” in conditional statement?
- Query “Category A” + 1 post from “Category B” – how?
- How to combine two or more WP_Query?
- Posts not showing per category after WP_Query?
- wp_query exclude word and category
- How can I query users by custom role?
- Removing duplicate values between two wordpress queries
- Exclude recently updated post from custom WP_Query using multiple loops
- get_posts output always same post
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- Limit number of posts in loop
- How do I get Woocommerce product variation name and variation description in a WP_Query?
- Does putting queries within loops cause an issue on WordPress?
- How to create Page templates for showing Blog posts in different layouts?
- Determining what post is displayed out of total posts found
- Is it normal that get_post() gets run 300 times and the content of those posts aren’t visible?
- WordPress Sub Category Archive, Show Extra Empty Page Number in Pagination
- How to get meta key list efficiently?
- Get posts having meta value between two numbers
- How to display last whole post on the homepage
- How do I skip wordpress’s 404 handling?
- Separate by Category Post Type
- Using modified ‘meta_key’ to set ‘orderby’ in WP_Query?
- Combine WP_Query with array of custom data to single loop without breaking the pagination
- Query posts in current category but not attachment format
- WP_Query with Pagination and orderby meta_value_num showing duplicates
- Optimising specific Query with ACF meta objects
- Slow getting posts from category
- Avoiding page loop
- Query Users by post count, last 30 days and display each users post count according to post type
- how do I exclude child categories from a wp_query?
- How to create a loop inside WP_Query?
- how to show only catergory titles on a page in wordpress
- Display post format post in the sidebar