add_rewrite_rule again

Here’s an example with template_redirect that loads your php script if the prm1 query var is set: // set up the rewrite add_action( ‘init’, ‘wpse36736_setup_rewrites’ ); function wpse36736_setup_rewrites(){ add_rewrite_rule( ‘snpv/([^/]+)’, ‘index.php?prm1=$matches[1]’, ‘top’ ); } // add query var add_filter(‘query_vars’, ‘wpse36736_query_vars’); function wpse36736_query_vars( $query_vars ){ $query_vars[] = ‘prm1’; return $query_vars; } // check the query var … Read more

WordPress Rewrite

assuming u is a custom query var, you have to first add it to the array of recognized query vars: function wpa_query_vars( $query_vars ){ $query_vars[] = ‘u’; return $query_vars; } add_filter(‘query_vars’, ‘wpa_query_vars’); Then add an internal rewrite rule that accepts anything appended to vendors and passes that as the u query var: function wpa_rewrite(){ add_rewrite_rule( … Read more

Permalinks for WooCommerce Categories and Subcategories

I was able to resolve this with the following code which generates rewrite_rules for each subcategory, which is preferred during matching since it’s more specific: function wpse_291143_generate_taxonomy_rewrite_rules( $wp_rewrite ) { global $wp_rewrite; $base = “shop”; $rules = array(); $terms = get_terms( array( ‘taxonomy’ => ‘product_cat’, ‘hide_empty’ => false )); foreach($terms as $term) { $term_children = … Read more

add_rewrite_rule with 3 or fewer matches?

Well, apparently lots of trial and error pays off! I used this code instead, where I reversed my add_rewrite_rules and now it works perfectly. // Remember to flush the rules once manually after you added this code! add_rewrite_rule( // The regex to match the incoming URL ‘our-work/our-year/([^/]*)/([^/]*)/([^/]*)/?’, // The resulting internal URL: `index.php` because we … Read more

Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url

WordPress parses incoming URLs with a list of regular expressions, the rewrite rules. The first regex that matches the URL “wins”, and determines what kind of query will be executed. You can see the rewrite rules and play with different URLs with my Rewrite analyzer plugin. Whether or not pages take priority over other rules … Read more