Comments (2)
Hi @boneus
You did not miss anything.
Adding a QueryRoute
means that when the URL you define is matched, WordPress will use the query arguments you define.
Adding a template
property to a route (directly or via a group does not really change) means that Cortex will add a filter to template_include
, which is a filter that is fired for all requests, including 404.
So what you described is the expected behavior:
- your URL matches
- the query is performed as required
- the
template_include
filter is added as required - your template includes some
body_class()
call in it, which because the query was 404, includeserror404
.
What you want is to "filter the template only if not 404". which is not something that Cortex can do out of the box.
But you have at least two different possibilities to obtain that result.
The first and probably simplest way is to change your archive-cpts.php
to contain on top of it something like this:
<?php
if (is_404()) {
locate_template(['404.php', 'index.php'], true);
return;
}
// rest of template here
This way when your template is loaded, in the case of a 404 request, it will look for a 404.php
template in the child theme if any, and then in theme, and if not found it will fall back to index.php
as WordPress would do.
An alternative would be to remove the filter added by Cortex when is a 404.
You can do that quite easily, because for 404 requests WordPress will trigger the 404_template
filter so you could do:
add_filter('404_template', function () {
remove_all_filters('404_template'); // Cortex adds a filter here as well
remove_all_filters('template_include');
}, 1); // act early, before Cortex
I've not tested this, but I expect it to work.
from cortex.
Thank you for the explanation.
I've actually already implemented something similar to the second approach but I wasn't sure if it's the right one :)
from cortex.
Related Issues (20)
- Overriding `template_include` hook HOT 6
- Sage 9 Integration HOT 6
- Simple example not fired. HOT 1
- About template HOT 2
- [Question] Is there any way to give Cortext routes a higher priority over WP routes? HOT 5
- Preserving variables? HOT 1
- [Question] could you describe how to do a paginated route? HOT 1
- [feature request] Closures as a value for the `template` setting HOT 4
- Render specific post/page/tax archive HOT 1
- How to add body classes depending on a Cortex route - the right way. HOT 2
- Current status for this project? HOT 4
- AJAX requests handling - how to set up CORS? HOT 3
- Routes "players" and "players/" are treated as same url HOT 2
- Abandoned packages and Parse error | PHP 8.0.11 HOT 1
- post__in not working HOT 1
- Wordpress 6 Changing on do_parse_request HOT 1
- Issue with wordpress v6 HOT 4
- get_post() does not work
- PHP dependency conflict: "psr/http-message" now requires PHP 7.2 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cortex.