Custom Taxonomy and Rewrite URL

Question

I’m fixing some custom templates. There is this custom taxonomies

add_action( 'init', 'custom_taxonomies', 0 );
function custom_taxonomies() {
register_taxonomy('news_category', 'stfp_news', array(
    'hierarchical' => true,
    'show_admin_column' => true,
    'label' => __('Categories'),
    'show_ui' => true,
    'query_var' => false,
    'rewrite' => array(
        'slug' => 'about/news/category'),
    'singular_label' => __('Category')) );
register_taxonomy('news_tag', 'stfp_news', array(
    'hierarchical' => true,
    'show_admin_column' => false,
    'label' => __('Tags'),
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array('slug' => 'about/news/tag'),
    'singular_label' => __('Tag')) );
}

And rewrite it after the news_category so they will format like

/about/news/press
/about/news/event

This is the rewrite rule i’ve been writing

add_rewrite_rule('^news/press/page/([0-9]+)/?$', 'index.php?news_category=press&paged=$matches[1]', 'top');
add_rewrite_rule('^news/notes/page/([0-9]+)/?$', 'index.php?   news_category=notes&paged=$matches[1]', 'top');
add_rewrite_rule('^news/events/page/([0-9]+)/?$', 'index.php?news_category=events&paged=$matches[1]', 'top');

If i try to remove word ‘category’, the url wont work. It seems the rule need 3 url segment like /about/news/category or any words as long as it have 3 segment. Any thoughts? Thanks before.

0
, , Chimenk 8 years 2015-08-28T02:03:09-05:00 0 Answers 67 views 0

Leave an answer

Browse
Browse