1

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

1 Answer 1

0

Isn't what you are trying to achieve the point of the rewrite slug? e.g.

if you have a news category as press and another as event then simply changing

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')) );

to

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'), // this line changed
'singular_label' => __('Category')) );

would then mean that a url of: http://yourdoimain/about/news/events would only show posts that belong to the events news_category.

or am I missing something?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.