I’m trying to get to where I can create a pretty URL for a custom post type (The end goal being to add a unique value to the query string so I can leverage page caching). So for example the original developer has /boats/page/1/
working fine and via add_query_arg
I can get /boats/page/1/?zip=05443
. I’d like to turn that into /boats/page/1/zip/05443/
and have tried via rewrite rules but am either missing something or the rewrite rules are not being called. Here is the rewrite rule I added.
$rules = array(
'^boats/page/(d+)/zip/(d+)/?$' => 'index.php?post_type=boat&paged=' . $wp_rewrite->preg_index(1) . 'zip=' . $wp_rewrite->preg_index(2)
);
$wp_rewrite->rules = array_merge($rules, $wp_rewrite->rules);
This is being called as part of a hook into generate_rewrite_rules
.
I can get the URLs to look correct but they generate a 404 when I click them. Any help would be greatly appreciated!