Remove custom post type slug but keep related category taxonomy permalink

When registering your custom post type have you tried to disable with_front in your rewrite array? For example, using an example for the post type book: add_action( ‘init’, ‘codex_book_init’ ); /** * Register a book post type. * * @link http://codex.wordpress.org/Function_Reference/register_post_type */ function codex_book_init() { $labels = array( ‘name’ => _x( ‘Books’, ‘post type general … Read more

WordPress custom post type rewrite rule matches all pages returning 404

I managed to find a solution thanks to Milo‘s previous answers on other related questions. I found this particular post Remove base slug in CPT & CT, use CT in permalink to be extremely helpful. My initial CPT with grandparent relationship rewrite remains the same: function cpt_child(){ $args = array( //code ‘rewrite’ => array( ‘slug’ … Read more

Rewrite in plugin

You’re almost there, but your understanding of how rules work is slightly off. Also I would recommend using the page_rewrite_rules filter: function wpse_224942_page_rewrite_rules( $rules ) { global $wp_rewrite; /* Don’t forget to change “my_query_var” in the rewrite rule too */ $new_rules = array( ‘bz/([^/]+)/?$’ => $wp_rewrite->index . ‘?pagename=bz&my_query_var=” . $wp_rewrite->preg_index( 1 ), ); return $new_rules … Read more

Rewrite rule pagination on different url levels

I have added extra rewrite rules for pages with no item_width and item_height in combination with pagination as follows: /** * Adds rewrite rules for shop category */ function gtp_add_shop_rewrite_rules() { // shop-category/category/item_width/item_height/page/2/ add_rewrite_rule( ‘^shop-category\/([^/]*)\/([^/]*)\/([^/]*)\/page\/([0-9]*)$’, ‘index.php?shop-category=$matches[1]&item_width=$matches[2]&item_height=$matches[3]&paged=$matches[4]’, ‘top’ ); // shop-category/category/page/2/ add_rewrite_rule( ‘^shop-category\/([^/]*)\/page\/([0-9]*)$’, ‘index.php?shop-category=$matches[1]&paged=$matches[2]’, ‘top’ ); // /shop-category/category/item_width/item_height/ add_rewrite_rule( ‘^shop-category\/([^/]*)\/([^/]*)\/([^/]*)$’, ‘index.php?shop-category=$matches[1]&item_width=$matches[2]&item_height=$matches[3]’, ‘top’ ); // /shop-category/category/item_width/ add_rewrite_rule( … Read more