permastruct for custom post type not working in one of four cases

You’re currently placing your rewrite rules in the global scope, which means they execute as soon as your file is loaded, which may be too early. Instead try adding them on the init hook, or rewriting them to use the generate_rewrite_rules filter instead, e.g.: add_action(‘generate_rewrite_rules’, ‘themes_dir_add_rewrites’); function themes_dir_add_rewrites() { $theme_name = next(explode(‘/themes/’, get_stylesheet_directory())); global $wp_rewrite; … Read more

Rewrite Rules for Multiple (more than 2) Taxonomies

You could try something like this: function custom_rewrite( $wp_rewrite ) { $feed_rules = array( ‘product-category/(.+)/material/(.+)/color/(.+)’ => ‘index.php?product_cat=”. $wp_rewrite->preg_index(1).”&pa_material=”. $wp_rewrite->preg_index(2).”&pa_color=”. $wp_rewrite->preg_index(3) “product-category/(.+)/color/(.+)’ => ‘index.php?product_cat=”. $wp_rewrite->preg_index(1).”&pa_color=”. $wp_rewrite->preg_index(2) “product-category/(.+)/material/(.+)’ => ‘index.php?product_cat=”. $wp_rewrite->preg_index(1).”&pa_material=”. $wp_rewrite->preg_index(2) ); $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules; } // refresh/flush permalinks in the dashboard if this is changed in any way add_filter( “generate_rewrite_rules’, ‘custom_rewrite’ ); It … Read more

Regex in add_rewrite_tag not accepting OR operators?

I don’t know what’s wrong but I can suggest: Use Rewrite Rules Inspector or similar to see where your %psubject% rule is and if its pattern ((option1|option2|option3)) has been added correctly. Test http://example.com/somecategory/option1/this-is-the-post-title with the Inspector to see which rule matches. Open http://example.com/somecategory/option1/this-is-the-post-title (when it shows home.php) with the Debug Bar plugin and look at … Read more