function add_my_rule() {
global $wp;
$wp->add_query_var('args');
$wp->add_query_var('arg_username');
add_rewrite_rule('writer/([0-9]+)/([^/]*)/page/([0-9]+)','index.php?pagename=writer&args=$matches[1]&arg_username=$matches[2]&paged=$matches[3]','top');
add_rewrite_rule('writer/([0-9]+)/([^/]*)','index.php?pagename=writer&args=$matches[1]&arg_username=$matches[2]','top');
/*global $wp_rewrite;
$wp_rewrite->flush_rules();*/
}
add_action('init', 'add_my_rule');
This should do the trick. One rewriterule for writer/user_id/username (username isn’t used in the rewriterule but is necessarily to make it work. The second rewriterule is the same except that it adds pagination.
EDIT: added arg_username in code above.
Related Posts:
- Custom pages with plugin
- Add rewrite rule to permalink structure
- add_rewrite_rule, plugin activation and plugin deactivation
- flush_rewrite_rules not working on plugin deactivation, invalid URLs not showing 404
- Custom rewrite rule is not picked by WordPress
- Does flush_rewrite_rules() remove all rules added by other plugins as well as mine?
- Add_rewrite_rule doesn’t add custom url in plugin
- How can I rewrite a plugin generated URL?
- flush_rewrite_rules() not working on plugin activation
- WordPress custom URL Rewrites redirecting not masking
- How does WP handle multiple matching rewrite rules?
- Custom rewrite rules not working with WPML
- How to Create a Custom Slug for Tags and Categories with a prefix or suffix?
- Custom url rewriting
- URL rewrite with external JSON query
- WordPress rewrite rules not working
- Do rewrites added with add_rewrite_rule() persist after plugin deletion?
- i want to rewrite my custom plugin url
- add_rewrite_rule to load different page, without changing URL in browser
- WordPress rewrite rule depend on meta values not ids
- Change custom rewrite rule when permalink is updated/changed
- Custom pages with plugin
- Apache rewrite rules and wordpress problem
- WP Job Manger change jobs url (NOT slug)
- How Do I add a redirect rule to WordPress?
- What is the best way to output plugin result in certain url
- Using rewrite rule to access a view of a plugin from home page
- flush rewrite rules doesn’t flush them (still got 404)
- Woocommerce different URL for every table placed in the restaurant
- Author Specific URL’s in WordPress
- Nested CPT URLs + Posts 2 Posts
- How to add rewrite rules and pagination to retrieve attachments files?
- custom taxonomy and custom post type url conflict
- Change settings of get_post_type_object
- Rewrite url without flushing the database?
- Custom page slug without creating a WP page
- WordPress URL redirect
- Checking that the Rewrite API is available
- Remove rewrite rules generated by plugin during deactivation
- Why slash is removed after domain?
- how to change the verification url of pie register plugin of wordpress?
- Plugin appends ugly URL string to index
- Is it possible to use multiple post_name, post_title and post_content?
- register_taxonomy and variable rewrite slug
- Problem with Author page redirect
- URL rewrite of independent plugin?
- Plugin generated taxonomies’ permalinks with custom placeholders
- Redirect to another page using contact form 7? [closed]
- Remove .htaccess portion upon plugin deactivation?
- Locked out of admin panel after installing HC Custom WP-Admin URL [closed]
- Edit Permalink Structure For Custom Post Type or Modify .htaccess?
- How to customize a title by passing query string?
- WordPress plugin url for form submit
- Creating author Specific page URL
- rewrite_rules() not applying rules on plugin activation only after permalinks menu is clicked
- Username Variable in custom links?
- How to rewrite URL and get the values?
- Passing value as hidden parameter to next page
- How to force load a page in plugin?
- How to embed a new string in url?
- rewrite file to wordpress
- TranslatePress | secondary language category/sub-category not working correctly “`/%category%/%postname%/“`
- can’t install any wp plugins [duplicate]
- Change language on website and change currency with url query
- Hidden permalink different from displayed permalink
- Having a problem with rewrite_rules and rewrite_tags – url not rewriting properly and query var missing
- Rewrite/Change custom taxonomy slug
- Custom Rewrite Rule Removing Query String
- one url for all pages
- Add custom WordPress admin page with pretty url via code
- How To Use htaccess to Rewrite Link Structure for a Page that is Generated Programatcially
- plugin: rewrite rules are lost when WP updates
- How to give .html extension to just one post not all post
- URL Rewrite 404
- WordPress drop domain alias
- catch urls with specific pattern and show specific content for them by plugin
- I am trying to rewrite urls in WordPress, but its not working
- Get custom term link archive with prefix
- How to regenerate slugs for categories and tag converting non-Latin characters?
- Change default url to plugin custom post type
- add_external_rule – rules deleted when visiting permalinks page
- How to disable wordpress page rewrite rule?
- Disable default posts (Posts,Pages,Comments and Media) in wp-admin
- Creating custom URL for async content
- URL RewriteRule doesn’t work when using WP Database Participants in my WordPress website
- Rewrite URL to plugin file
- How to programatically create a simple HTML page using the permalink of a WordPress post?
- How To Rewrite WordPress Pages URL Only?
- custom url with custom post
- How to remove post redirects
- How to get the parameters on page and avoid 404?
- URL Rewriting from a Plugin based on custom values
- How to create custom content on custom page from plugin?
- Plugin with custom domain
- How to get the real address from a url (permalink)
- Remove base from the custom post type URL [duplicate]
- How can I output completely custom content with plugin while still having header, footer, sidebar etc [closed]
- Please Check this ‘.htaccess’ File
- URL Redirect on GoDaddy platform [closed]
- How to rewrite URL using .htaccess in WordPress Plugin