Open Etheliene opened 2 years ago
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?
~~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)
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)
I have the following routes in my functions.php:
According to the documentation everything should work fine and I can load the initial Route 'verzeichnis' - but as soon as I try to load one of the sub-routes I get the default behaviour of the index.php which shows my posts.
What I am wondering is if it would be possible to define a single dynamic route eg.
where the parameters that are here dynamic are optional but not necessary.
Please update the documentation and or let me know where I could find some sort of support if this is not the right place. Thanks in advance!