Articles of add rewrite rule

Does flush_rewrite_rules() remove all rules added by other plugins as well as mine?

I am developing a plugin, and am using add_rewrite_rule followed by flush_rewrite_rules during plugin activation. On plugin deactivation I am using just flush_rewrite_rules to remove the rule that I had added. Now let’s assume another plugin had also added a rewrite rule. Would calling flush_rewrite_rules not remove this other plugins rewrite rule as well, even […]

Rewrite custom post type url's adding meta box values

I’ve got these custom post types (CPT) and meta boxes: Movies (CPT) Genre (Meta box) Genres (CPT) If one movie is called Die hard then I want the permalink to be: /genres/action/die-hard This is easily fixed by setting the movie-CPT to ‘rewrite’ => false and use this code instead: add_action(‘init’, ‘rb_add_rewrite_rules’); add_filter(‘post_type_link’, ‘rb_create_permalinks’, 10, 3); […]

add_rewrite_rule isnt working, not getting added to rules array, why?

I’m trying to add a new rewrite rule but it doesn’t seem to be getting added to the array and it certainly isn’t working. I’m trying to get this URL, dult.dev/lists/games/destiny, to take me from a list view of /lists/games/ (which works just fine) to a single post view of that particular post. My rewrite […]

why does add_rewrite_rule refresh and loose url variables

I am using: add_action( ‘init’, ‘add_author_rules’ ); function add_author_rules() { add_rewrite_rule( “support/([^/]+)/?”, “index.php?category=$matches[1]”, “top”); } in the themes/function.php when I enter the address: http://localhost/support/funding the url changes to: http://localhost and the variable is not set: print_r($_GET); $category = get_query_var(‘category’); echo ‘!’.$category.’!’; both give an empty result the .htaccess is unchanged and is: # BEGIN WordPress […]

add_rewrite_rule to pass entire path as a single parameter

I want to rewrite an url and pass the whole path as a parameter. Something like: www.example.com/csearch/foo1/bar1/foo2/foo3/bar4 => www.example.com/index.php?page_id=23&csearch=foo1/bar1/foo2/foo3/bar4 The script on page_id 23 will parse the content of csearch. The path after /csearch/ varies in length. It can have 0 or 30 levels. I have a working solution for only one level www.example.com/csearch/foo1 => […]

Custom rewrite rule for backend/admin?

I would like to create a custom rewrite rule that will take the URL: http://domain/submit-project/add but display http://domain/wp/wp-admin/post-new.php?post_type=project Is there any way to do this? I am trying to add the rewrite rule so in my theme’s functions.php add_action( ‘init’, ‘add_custom_rules’ ); function add_custom_rules() { add_rewrite_rule( “^submit-project/add”, “/wp/wp-admin/post-new.php?post_type=project”, “top”); } I’ve tried flushing the rules, […]

flush_rewrite_rules() cancels the effect of add_rewrite_rule()

As one of my plugin’s features, I’m trying to define a custom url structure, like http://www.mysite.tld/foo/{action}. I’m using add_rewrite_rule() along with flush_rewrite_rules() on plugin activation, which works as expected. Until flush_rewrite_rules() gets called again, during another request, either by hand or by enabling another plugin that does so. When this happens, my rewrite rule suddenly […]

Does WP Have a Function To Generate .htaccess RewriteCond?

I know that I can edit .htaccess manually and add a RewriteCond statement inside, but I need to build a plugin that does this the proper way by using WP rewrites which then get pushed into .htaccess with flush_rewrite_rules(). I need RewriteCond in this case. Does WP have some obscure function that lets me push […]

query_vars in plugin not working?

I have a problem writing a plugin for wordpress. First, I register a new query_var and add a new rewrite rule: function nng_users_query_vars( $vars ) { array_push( $vars, ‘nng_users’ ); return $vars; } add_filter(‘query_vars’, ‘nng_users_query_vars’); function nng_users_rewrite_rules( $rules ) { $newrules = array( ‘benutzer/([^/]+)/?$’ => ‘index.php?pagename=nng_users&nng_users=$matches[1]’ ); $finalrules = $newrules + $rules; return $finalrules; } […]

Pagination problem

I have two custom rewrite rules: add_rewrite_rule(‘foo/bar/?’, ‘index.php?post_type=foo’, ‘top’); add_rewrite_rule(‘foo/bar/([a-z]+)/?’, ‘index.php?post_type=foo&bar=$matches[1]’, ‘top’); Which gives me posts that match a custom variable bar. However, I want to handle pagination too, thus when a number succeeds /bar/ wordpress should treat it as a page number. I wrote: add_rewrite_rule(‘foo/bar/([0-9]+)/?’, ‘index.php?post_type=foo&paged=$matches[1]’, ‘top’); In my custom function which is attached […]