Search code examples
wordpresspermalinks

Wordpress Permalinks structure taxonomy_termname/post_name


I am developing a website and I registered a custom post type called Book and taxonomy Genre for it. I want a permalink to be like www.mysite.com/genre_name/post_name

Code:

register_post_type( 'reviews', array(
    'label' => 'Books',
    'description' => '', 
    'public' => true, 
    'show_ui' => true, 
    'show_in_menu' => true, 
    'capability_type' => 'page', 
    'hierarchical' => true, 
    'rewrite' => array('slug' => 'book'), 
    'query_var' => true, 
    'exclude_from_search' => false, 
    'supports' => array( 'title','editor','page-attributes', 'comments', 'author', 'revisions' ) 
    ) 
);

What should I do? Any help would be appreciated.


Solution

  • I found a way by creating custom handler for post_type_link and pre_get_posts.

    I prepared url as my client expecting using post_type_link.

    I added rewrite rules for each taxonomy term i wanted. and flush the rules.

    This way it works.