Monkey Man Rewrite Analyzer says my rule will trigger but it doesn’t

I installed Monkey Man Rewrite Analyzer, i got a rule installed, it shows in the list, if i test it with monkey man it says it will fire but it doesn’t in reality, whats wrong?

add_action('init', array($this, 'register_crr_jsonwebservice'), 99);

public function register_crr_jsonwebservice() {

    //Add the rewrite rule for this specific json controller
    add_rewrite_tag( '%ticket%', '([a-zA-Z0-9]+)');
    add_rewrite_rule( 'cjson/fullticket/([a-zA-Z0-9]+)/', 'index.php?p=1312&ticket=$matches[1]', 'top' );
    flush_rewrite_rules();

}

Test this rule in MMRA:

Read More

cjson/fullticket/231412tgsxcasfasdfas/

Works fine, test it out on wordpress directly copying the same url? 404, not found… what am i doing wrong?

Related posts

Leave a Reply

1 comment

  1. Honestly, can not debug your code, but this one works:

    function register_crr_jsonwebservice( $wp_rewrite ) {            
        //Add the rewrite rule for this specific json controller
        add_rewrite_tag( '%ticket%', '([a-zA-Z0-9]+)');
        $wp_rewrite->rules = array(
            'cjson/fullticket/?([a-zA-Z0-9]{1,})/?$' => $wp_rewrite->index . "?page_id=243&ticket=".$matches[1]
        ) + $wp_rewrite->rules;
    } 
    
    add_action( 'generate_rewrite_rules', 'register_crr_jsonwebservice' );
    

    Do not call flush_rewrite_rules(); from this function – will lead to an error. And maybe add_rewrite_tag will have to be caled from separate function on init – have’t tested that.