We have added a custom rewrite_rule to our site to allow for a pretty inbound link to be parsed and handled properly. Links are constructed as domain.com/meetings/faculty/someIDnumber
add_action( "init", "pleasing_permalinks" );
function pleasing_permalinks() {
add_rewrite_tag( '%hash%', '([^&]+)' );
add_rewrite_rule(
'meetings/faculty/([^/]+)/?$',
'index.php?p=1598&hash=$matches[1]',
'top'
);
//flush_rewrite_rules();
}
Rewrite Analyzer approves of the above but when we test with actual links in the browser, the embedded ID number is not preserved. What are we missing here?
If
faculty
is a child page ofmeetings
, the rule should be:pagename=meetings/faculty
instead ofp=1598
EDIT- or alternately:
page_id=1598
instead ofp=1598
Have you tried using the first index rather than the second?
Arrays in PHP start at 0 not 1
Just tested your code on a clean WP installation and was able to get the variable with:
Edit: As written in the correct answer ‘p’ must be replaced with ‘page_id’ to be able to keep the variables when redirecting to a post of type ‘page’.