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!

  • Anyone? I'm struggling here and I'm sure I'm missing something small. I did see that the rewrite rules only get inserted into the DB if you update permalinks and if I echo out $wp_rewrite I do see them (on the permalinks admin page). Any suggestions / pointers would be greatly appreciated! – JSP Nov 16 '12 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.