rewrite_rule() not preserving the query string

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?

3 Answers
3

If faculty is a child page of meetings, the rule should be:

add_rewrite_rule(
    'meetings/faculty/([^/]+)/?$',
    'index.php?pagename=meetings/faculty&hash=$matches[1]',
    'top'
);

pagename=meetings/faculty instead of p=1598

EDIT- or alternately:

add_rewrite_rule(
    'meetings/faculty/([^/]+)/?$',
    'index.php?page_id=1598&hash=$matches[1]',
    'top'
);

page_id=1598 instead of p=1598

Leave a Comment