I'm attempting to implement a rewrite rule so I can introduce a variable into my CPT's single page template. Basically I'm trying to include 'all' between my CPT's slug name of work
and the category in the URL:
http://localhost/work/all/corporate/cognitive-puzzles/
The original URL should of course work as well:
http://localhost/work/corporate/cognitive-puzzles/
Here's what I have for my rewrite:
function wire_alternate_pdp_url() {
global $wp;
$wp->add_query_var('mode');
add_rewrite_rule('work/all/([^/]*)/([^/]*)/?', 'index.php?pagename=$matches[2]&mode=all', 'top');
}
This almost works but for two issues. First being, the URL in my browser switches back to the form with the missing all/
path. Second and more importantly, I get nothing for a mode
within my single-project.php:
<?php
$mode = get_query_var('mode');
echo $mode;
?>
This prints out nothing.
Any ideas on what I might be missing here? I feel I'm close but something isn't quite right.
Thanks in advance!
edit: forgot to mention, I'm running 3.6.1
wire_alternate_pdp_url
function (on which filter/action hook)?wire_alternate_pdp_url
on theinit
hook. I'm pretty certain the rule is matching. As an experiment, I changed the rule to this: add_rewrite_rule('work/all/([^/]*)/([^/]*)/?', 'index.php?pagename=foo&mode=all', 'top'); and this resulted in URLs redirecting to a foo page I had made.