0

Doing something wrong, can't figure out what..Any help is highly appreciated for sure!

I have a custom post type which I want to add query vars to in permalink structure.. So far so good....

This is wordking right: http://allehondenrassen.nl/kennel?artist=queen&genre=pop

This is not working: http://allehondenrassen.nl/kennel/queen/pop/

in my archive-kennels.php I added:

echo get_query_var('artist');
echo get_query_var('genre');

In functions.php I added:

add_filter('page_rewrite_rules', 'dvd_rewrite_rules');
function dvd_rewrite_rules($rules)
{
global $wp_rewrite;
// custom post type name
$dvd_post_type = 'kennels';
$dvd_rule = array(
    // Custom Rewrite Slug = kennel
    'kennel/(.+)/(.+)/?' => 'index.php?post_type=' . $dvd_post_type . '&artist=$matches[1]&genre=$matches[2]'
);
return array_merge($dvd_rule, $rules);
}


add_filter('query_vars', 'dvd_query_vars');
function dvd_query_vars($vars)
{
$dvd_vars = array(
    'artist',
    'genre'
);

return array_merge($dvd_vars, $vars);
}

Playing with this for hours but can't see the problem... Thanks in advance! Bas

1
  • I have not looked in-depth into your code. But have you flushed your rewrite rules? Settings > Permalink > Save Changes
    – Evan Yeung
    Nov 27, 2011 at 0:24

1 Answer 1

1

Yes I did, didn't help but thanks anyway! I fixed it by installing the dump environment plugin http://wordpress.org/extend/plugins/dump_env/

This way I was able to evaluate all existing rewrite rules. My custom rewrite rule was conflicting with an existing rewrite rule that WP generated for the custom post type by default.

I changed my rule

'kennel/ras/(.+)/(.+)/?$' => 'index.php?post_type=' . $dvd_post_type . '&artist=$matches[1]&genre=$matches[2]'

Now it works as it should! The dump env plugin, this is going to save me some development time in the future ;) Thanks!

1
  • 1
    You should also consider modifying your regex, It's going to behave unexpectedly. Better: ^kennel/ras/([^/]+)/([^/]+)/?$ Apr 6, 2012 at 2:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.