add_query_vars and add_rewrite_rules

You can see in this answer how add_rewrite_rules is being used, I don’t think it applies to your case at all. What you need to do is to redirect urls generated from the search from (I’m assuming something like site.com/?s=term) to a pretty URL. This article do it http://www.wptavern.com/how-to-make-the-wordpress-search-url-pretty

How do i change the search permanent links

This snippet should solve your problem. Just put it into your functions.php file. function my_insert_rewrite_rules( $rules ) { $newrules = array(); $newrules[‘search/([^/]+)/post_type/([^/]+)/?$’] = ‘index.php?s=$matches[1]&post_type=$matches[2]’; return $newrules + $rules; } add_filter( ‘rewrite_rules_array’,’my_insert_rewrite_rules’ ); function my_flush_rewrite_rules() { flush_rewrite_rules(); } add_action( ‘after_switch_theme’, ‘my_flush_rewrite_rules’ ); You will have to flush rewrite rules after adding this code, before it will … Read more

Rewrite url for custom post type

this will not work: ‘en/index.php?post_type=vinos’ there is no en/index.php, it has to be: ‘index.php?post_type=vinos’ if you need to detect en in the path, add a query var, then set that query var in your rewrite: function wpa_query_vars( $qvars ) { $qvars[] = ‘wpa_lang’; return $qvars; } add_filter( ‘query_vars’, ‘wpa_query_vars’ ); then in your rewrite rule: … Read more

Pretty Permalinks

You should add your own custom query variable first: function add_search_store_query_var($vars) { $vars[] = ‘search_store’; return $vars; } add_filter( ‘query_vars’, ‘add_search_store_query_var’); And then add rewrite rule: function add_search_store_rewrite_rule() { add_rewrite_rule(‘stores/([^/]+)$’, ‘index.php?page_id=<YOUR SEARCH PAGE ID>&search_store=$matches[1]’, ‘top’); } add_action(‘init’, ‘add_search_store_rewrite_rule’); You can then use get_query_var(‘search_store’); to get search term. Just remember to flush rewrite rules, before you … Read more

Using plus (+) sign instead of space (-) in WordPress URL

This isn’t possible without modifying a core file. The function WordPress uses for this is called sanitize_title_with_dashes You can find it in wp-includes/formatting.php on It doesn’t offer any filters, so you will need to make a change to this line: $title = str_replace( array( ‘%c2%a0’, ‘%e2%80%93’, ‘%e2%80%94’ ), ‘-‘, $title ); I wouldn’t recommend modifying … Read more

Handle category name URL rewrite before different post type slugs

After some brainstorming and a lot of trial and error with T5 Rewrite and HM Rewrite, I went for the simplest possible solution. The permalink was actually intercepted by WordPress so I didn’t need the additional rewrite rule (even though it didn’t hurt, other than performance). I left %category%/%post_id%/%postname% as the default custom permalink, and … Read more