I'm using WordPress 3.0.1 and I have made custom post-type called 'dienasgramatas'
. My plugin also makes custom rewrite rules for displaying all posts from this post type and even custom permalink structure to query posts with this post type coming from defined author, but I can't create rule for pagination:
This is the one that works:
$new_rules['dienasgramatas' . '/([^/]+)/?$'] =
'index.php?post_type=dienasgramata&author_name=' . $wp_rewrite->preg_index(1);
It gives this rewrite rule:
[dienasgramatas/([^/]+)/?$] => index.php?post_type=dienasgramata&author_name=$matches[1]
But this one:
$new_rules['dienasgramatas' . '/([^/]+)/page/?([0-9]{1,})/?$'] =
'index.php?post_type=dienasgramata&author_name=' . $wp_rewrite->preg_index(1).
'&paged=' . $wp_rewrite->preg_index(2);
Outputs this (faulty) rewrite rule:
[dienasgramatas/([^/]+)/page/?([0-9]{1,})/?$] =>
index.php?dienasgramata=$matches[1]&paged=$matches[2]
As you can see, post_type
is ignored and this rewrite rule does not work as it should.
Can someone tell me why it's not working or how to make it right?
filter for funcion:
add_filter('generate_rewrite_rules', 'add_rewrite_rules');
Full function is as follows:
function add_rewrite_rules($wp_rewrite) {
$new_rules['dienasgramatas' . '/([^/]+)/?$'] = 'index.php?post_type=dienasgramata&author_name=' . $wp_rewrite->preg_index(1);
$new_rules['dienasgramatas' . '/([^/]+)/page/?([0-9]{1,})/?$'] = 'index.php?author_name=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2) . '&post_type=dienasgramata';
$wp_rewrite->rules = array_merge($new_rules, $wp_rewrite->rules);
return $wp_rewrite;
}
Basic need is that i want to go to
www.example.com/dienasgramatas/admin/page/2
and get posts by 'admin' with post_type = 'dienasgramata' and second page (e.g. 10 post offset). Rewrite rule without page/2 works fine. Maybe it's a regex issue or query vars issue or how rewrite rules are assigned.
live site example:
http://dev.fiicha.lv/jb/dienasgramatas/juris/
- works ok
http://dev.fiicha.lv/jb/dienasgramatas/juris/page/2/
- does not work
at the bottom there are all rewrite rules and query vars
add_rewrite_rule()
? If you can post a complete example it will be easier to help you.