Support » Fixing WordPress » Custom Rewrite Rules Problem.

  • 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, 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 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 ( ) 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.

  • The topic ‘Custom Rewrite Rules Problem.’ is closed to new replies.