Comments (2)
Regarding optional route patterns, try /:one?/:two?/:three?
Haven't tried it but I think it should work.
Are you sure your WP_Query is ok?
Update:
Looks like I was wrong, there is no logic for checking for optional patterns.
You can Extend Routes class and add that logic.
Optional route patterns work (Didn't look in AltoRouter.php)
from routes.
you can write it like this:
// Routes::map('verzeichnis', 'my_cb');
// Routes::map('verzeichnis/:country', 'my_cb');
// Routes::map('verzeichnis/:country/:city', 'my_cb');
// Routes::map('verzeichnis/:country/:city/:rechtsgebiet', 'my_cb');
Routes::map('verzeichnis/:country?/:city?/:rechtsgebiet?', 'my_cb');
function my_cb($params) {
foreach($params as $key => $value){
switch($key){
case 'rechtsgebiet':
$filename = '-schwerpunk';
break;
case 'city':
$filename = '-city';
break;
case 'country':
$filename = '-country';
break;
default:
$filename = '';
break;
}
}
$query = array(
'posts_per_page' => 30,
'country' => $params['country'], // is this correct WP_Query?
'city' => $params['city'],
'rechtsgebiet' => $params['rechtsgebiet'],
// Add this if you want to optimize query
'no_found_rows' => true,
'ignore_sticky_posts' => true,
);
Routes::load(get_stylesheet_directory() . '/directory/directory' .$filename. '.php', $params, $query);
}
From the Documentation
$query
The query you want to use, it can accept a string or array just likeTimber::get_posts
-- use the standard WP_Query syntax (or a WP_Query object too)
from routes.
Related Issues (20)
- Make more (all?) AltoRouter options available HOT 2
- when WPML uses GET param as lang format HOT 4
- Image instead of the page HOT 3
- Update to newest Alto Router HOT 1
- PHP Warning: Creating default object from empty value HOT 4
- typo in description HOT 1
- Second route callback dont work in similar routes HOT 6
- Is this plugin deprecated now that it is being removed from Timber 2.0? HOT 2
- Bad phpdoc HOT 3
- ability to change HTTP status code within load() method?
- [Feature Request] Add route/template slug to <body> tag
- Load another page from argument
- Query parameter not working with Wordpress 6 HOT 6
- Custom Route with RSS Feed
- Library PHP Compatibility PHP 8.x
- Route /download/1.5.1 doesn't work with decimal numbers
- Fatal error in WordPress 4.6 HOT 5
- README for custom WP_Query is incorrect HOT 1
- AltoRouter version limitation HOT 1
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 routes.