2
votes

I have custom post type (portfolio) with two different categories, then I have 2 pages showing posts from each of both categories.

The url when I call the page is something like mysite.com/pagename where pagename has the same name of the portfolio category.

My problem is when I go in the single portfolio the url changes into mysite.com/portfolio/portfolio-name

Is there any way to show the portfolio category in the url instead? It should be like mysite.com/portfolio-category/portfolio-name

Thanks in advance.

2
For anyone landing here, this question covers the same topic, and includes an answer which works: stackoverflow.com/questions/23698827/…JoLoCo

2 Answers

0
votes

Yes, any of those are possible and configurable under Settings > Permalinks. Have a look at the Permalinks page for other possibilities.

One thing to note though, it's suggested to add a number at the beginning of your permalinks to reduce the number of rewrite rules WordPress has to generate to resolve all of your URLs.

-1
votes

Register Your Taxonomy as Below.

Here "portfolio" is your "Custom Post Type" And "portfolio-category" is your "portfolio category".

After adding this hook URL will display with "portfolio-category".As You want.

Try This will help you.

/* add action hook in function.php */
add_action( 'init', 'custom_function_toadd_taxonomyurl',0);
function custom_function_toadd_taxonomyurl() {

register_taxonomy( 'portfolio-category', array( 'portfolio' ), array(
        'hierarchical' => true,
        'label' => 'Portfolio Categories',
        'singular_name' => 'Portfolio Category',
        'show_ui' => true,
        'query_var' => 'portfolio-category',
        'rewrite' => array( 'slug' => 'portfolio-category')
    ));

}