A part of regular expression in add_rewrite_rule function not working
A part of regular expression in add_rewrite_rule function not working
A part of regular expression in add_rewrite_rule function not working
using htaccess to check for cookie on permalink then conditionall rewrite with query parameter
“SAVE PERMALINKS” does more than FLUSH_REWRITE_RULES?
how to have same rewrite rules for 2 different post type?
Sorted in the end. As Milo suggested I didn’t need the calls to add_rewrite_tag. The following code works: /** * Custom rewrite rules */ function my_rewrite_rules() { add_rewrite_rule( ‘^([^/]*)/([^/]*)/([^/]*)?’, ‘index.php?post_type=room&room=$matches[3]’, ‘top’ ); add_rewrite_rule( ‘^([^/]*)/([^/]*)?’, ‘index.php?post_type=house_type&house_type=$matches[2]’, ‘top’ ); add_rewrite_rule( ‘^([^/]*)/?’, ‘index.php?post_type=development&development=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘my_rewrite_rules’ );
There are a couple of issues with your regular expression: ^model_more/(\d*)$ ^— Says “match start of line” In your URLs, the start of the line is actually /model/, so ^model_more will never match. Instead, try a regex like this: ^model/[^/]+/model_more/(\d+)/?$ [^/]+ says “match anything except /, since I would guess there are multiple models under … Read more
I have tested your code and it works just fine. The thing that I think you are missing is flushing the permalinks by going to WP Admin -> Settings -> Permalinks and click Save Changes.
Rewrite Rules, Query Vars and Pagination
WordPress matching URLs with trailing tildes code correction
In addition to setting has_archive you need to set rewrite when you define the CPT. I replaced $archives because your code snippet does not have it defined. $rewrite = array(‘slug’ => ‘my-cpt-type’, ‘with_front’ => false); $download_args = array( ‘labels’ => $labels, ‘public’ => true, ‘publicly_queryable’=> true, ‘show_ui’ => true, ‘show_in_menu’ => true, ‘query_var’ => true, … Read more