Custom Rewrite Rules Problem. (1 post)

  1. Christian1012
    Posted 1 year ago #

    Hello, I'm using 3.8.1, my custom theme based off _s, local copy.

    I'm using Rewrite API to create a simple rule. I have a page on my site, example.com/db-admin. This is a page created by WordPress, ie. index.php?p=5487 or whatever. I want to display different things on this page, based on custom query vars, as is the WP way.

    So example.com/db-admin/123456/edit would actually be index.php?p=5487&tour_number=123456&tour_page=edit.

    So I created the following rules:

    function eadb_add_rewrite_rules(){
        global $wp_rewrite;
        $wp_rewrite->add_rewrite_tag( '%tour_number%', '([0-9]{6}})', 'tour_number=');
        $wp_rewrite->add_rewrite_tag( '%tour_page%', '(edit|add|registry)', 'tour_page=');
        $wp_rewrite->add_rule( '^db-admin\/([0-9]+)\/(edit|add|registry)', 'index.php?p=10300&tour_number=$matches[1]&tour_page=$matches[2]', 'top');
    add_action( 'init', 'eadb_add_rewrite_rules' );

    However, the query vars created were never passed to the page, and the url was usually rewritten incorrectly. I have tried variations for the regex, but I don't that's the problem. Right now, with what I have above, I see my rule in the rules array of the global rewrite object, and my tags as empty query vars. However, when requesting the url in the structure I have above ( example.com/db-admin/123456/edit ) the matched rule is:

    (.?.+?)(/[0-9]+)?/?$ | index.php?pagename=$matches[1]&page=$matches[2]Array

    ...so I am at a loss. Any help would be killer. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.