• Hello, I try to make custom rewrite rule for my post type. I tried many different methods, none of that worked. So I decided to copy basic rule_rewrite function from codex and tried to apply to my site

    function new_rewrite(){
    
    	add_rewrite_rule('^leaf/([0-9]+)/?', 'index.php?page_id=$matches[1]', 'top');
    
    	flush_rewrite_rules();
    }
    
    add_action( 'init', 'new_rewrite' );

    In $wp_rewrite; I see that rule as an element of extra_rules_top object:
    ^leaf/([0-9]+)/?
    “index.php?page_id=$matches[1]”

    So I think it is applied, but it does not work, even if I perform flush manually from admin panel. If write URL /index.php?page_id=7 it sends to me a right page, but I write /leaf/7/ it gives 404 error. So even basic example rule does not work as it should.

    Could you make it work in a right way? If you do please tell me how it actually works…

The topic ‘how to make add_rewrite_rule work?’ is closed to new replies.