Default category link for a custom category is a broken link

I found that the reason flush_rewrite_rules(); wasn’t working was because switch_to_blog doesn’t re-initialize some of the properties of $wp_rewrite (not to mention other parts of WP), so flush_rewrite_rules was still generating some of the rules based on the permalink structure of the current blog (which is not the same), rather than the switched-to blog (84). … Read more

How to properly rewrite url by custom var

So, first off, never flush rewrite rules on every page load. Better to do it on plugin activation one time. Step 1: add the rewrite rule: add_action( ‘init’, ‘wpse26555_add_rewrite’ ); function wpse26555_add_rewrite() { // You should probably rewrite to index.php instead of shop.php? add_rewrite_rule( ‘/shop/brand/([^/]+)/?$’, ‘index.php?brand=$matches[1]’, ‘top’ ); } Step 2: add the query var … Read more

How to rewrite custom post type with custom taxonomy urls?

When you are adding a custom taxonomy you are able to declare a rewrite slug – $labels = array( ‘name’ => _x(‘Name’, ‘taxonomy general name’), ‘singular_name’ => _x(‘Singular Name’, ‘taxonomy singular name’), ‘search_items’ => __(‘Search Items’), ‘all_items’ => __(‘All Names’), ‘parent_item’ => __(‘Parent Item’), ‘parent_item_colon’ => __( ‘Parent Ites:’), ‘edit_item’ => __(‘Edit Item’), ‘update_item’ => … Read more

Rewriting URLs in WordPress

‘event/industry/(.+)/?$’ The above is the URL that will be rewritten behind the scenes. The brackets create what is known as a “backreference”. ‘index.php?post_type=eg_event&industry=’ . $wp_rewrite->preg_index(1) The above is the actual URL that will be served to the browser. So, http://yourdomain.com/event/industry/abc/ matches the rule “event/industry/(.+)/?$”. The term ‘abc’ becomes a backreference with index 1, because it … Read more