Articles of rewrite rules

Force a specific template based on the URL

When a user browses to a URI beginning with “/forums”, WordPress should call a specified template. For example, all of these URLs: mysite.com/forums mysite.com/forums/questions mysite.com/forums/questions/1/my-question mysite.com/forums/questions/ask mysite.com/forums/users … should call the following template: mytheme/page-forums.php I believe this involves WP_Rewrite, but I have no clue what to do from here. Any ideas?

Remove rewrite rules generated by plugin during deactivation‎

I have a simple plugin like the following add_action(‘generate_rewrite_rules’, function ($wp_rewrite) { $wp_rewrite->rules = xxx + $wp_rewrite->rules; }); if (is_admin()) { register_activation_hook( __FILE__, function() { flush_rewrite_rules(FALSE); }); register_deactivation_hook(__FILE__, function() { flush_rewrite_rules(FALSE); }); } When I activate this plugin, the rewrite rule is being updated and in effect, cool! However, when I deactivate the plugin, the […]

Custom query_vars and parse_request on wp-admin

I’ve read this post http://wordpress.org/support/topic/query-vars-in-admin and although it’s quite an old question, it suits me perfectly. I’m trying to accomplish what I already posted here: Rewrite rule for admin-ajax.php But in the code below, only the first filter gets called while in wp-admin: add_action(‘init’, array(‘MYCLASS’, ‘add_custom_rewrite_rules’), 10, 1); add_action(‘query_vars’, array(‘MYCLASS’, ‘add_custom_query_vars’), 10, 1); add_action(‘parse_request’, array(‘MYCLASS’, […]

Why is add_rewrite_endpoint incompatible with /%category%/%postname%/ permalink structure?

I’ve added a myvar/myvalue rewrite endpoint to EP_ALL which can be added to any URL of a WP installation and a WP plugin will act upon it. That part is cool but it doesn’t work when the permalink structure is /%category%/%postname%/. It works well with all the built in, selectable structures. There could be other […]

Do I need to flush rewrite rules when creating new user if using custom author rewrite rules?

I am using custom urls for my author pages like this: http://site.com/author_name After I create a new user, that author page appears as not found; however, if I update my permalink structure from admin panel, the author page is found. So, is it necessary to flush rewrite rules after a new user is created? Is […]

How to set up Author archives with sub category URL

So i have a site where i have used the authors.php page so that i can display individual user’s profile pages.. the url then looks something like: http://mydomain.com/author/test/ What i would like to do is have it so that I can add subpages to this that are common for each user ie: http://mydomain.com/author/test/liked-posts/ where i […]

add_rewrite_rule not working for me

I have the following rewrite tags defined: // ADD REWRITE TAG FOR ‘VEHICLE MAKES’ add_rewrite_tag(‘%make%’,'([^&]+)’); // ADD REWRITE TAG FOR ‘BODY STYLES’ add_rewrite_tag(‘%body-style%’,'([^&]+)’); // ADD REWRITE TAG FOR ‘OTHER TOPICS’ add_rewrite_tag(‘%topic%’,'([^&]+)’); I’m trying to create a custom rewrite for each one of these that can apply to any page the variables exist. I’ve been reworking […]

Does it still make sense using json endpoint ep_mask now that there's the new rest api?

I was wondering… Maybe I don’t get the point here, don’t know. I think that the rewrite api is still usefull for creating beautiful frontend urls for regular users. But I’m not sure on adding a json endpoint via ep_masks (for example: https://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/). Isn’it a thing already covered by the new rest api? Am I […]

Rewrite WordPress URL to show CPT meta field data

I’m stuck in need of a rewrite rule. I have set up a custom post type for ‘Books’, each book has a repeatable field (using ACF Pro) for chapters. I have added a query_var for chapter using the code below… // Add chapter to query vars array function add_query_vars_filter( $vars ){ $vars[] = “chapter”; return […]

Parent & Child Taxonomy slugs in custom post permalink

I’ve registered a custom post type “book” and a taxonomy “authors” as below: add_action( ‘init’, ‘post_book_init’ ); function post_book_init() { $labels = array( ‘name’ => ‘BOOKs’, ‘singular_name’ => ‘BOOK’, ‘menu_name’ => ‘BOOKs’, ‘name_admin_bar’ => ‘BOOK’, ‘add_new’ => ‘Add New’, ‘add_new_item’ => ‘Add New BOOK’, ‘new_item’ => ‘New BOOK’, ‘edit_item’ => ‘Edit BOOK’, ‘view_item’ => ‘View […]