Hi,
Thank you for contacting us and I'd be happy to assist.
The permalink structure that you described is what is available out of the box and is considered conventional.
On my test website, I was able to achieve the changes you're planning, through these steps:
1. In the 'portfolio-category' taxonomy's settings, I added the following text in the Rewrite field:
/portfolio
( screenshot: taxonomy-settings.png )
After this change, the taxonomy archive page URL will become
/portfolio/category-slug
2. In the 'portfolio' post type's custom URL rewrite settings, I included:
/portfolio/%portfolio-category%
( screenshot: custom-post-type-settings.png )
3. Next, I include the following custom code, in the active theme's 'functions.php' file:
function change_link_portfolio( $post_link, $id = 0 ) {
$post = get_post( $id );
if( $post->post_type == 'portfolio' )
{
if ( is_object( $post ) ) {
$terms = wp_get_object_terms( $post->ID, array('portfolio-category') );
if ( $terms ) {
return str_replace( '%portfolio-category%', $terms[0]->slug, $post_link );
}
}
}
return $post_link ;
}
add_filter( 'post_type_link', 'change_link_portfolio', 99, 3 );
function generated_rewrite_rules_portfolio() {
add_rewrite_rule(
'^portfolio/(.*)/(.*)/?$',
'index.php?post_type=portfolio&name=$matches[2]',
'top'
);
}
add_action( 'init', 'generated_rewrite_rules_portfolio' );
This code finds the '%portfolio-category%' string from the single portfolio page's permalink and replaces it with the attached 'portfolio-category' term's slug.
4. After making this change, please flush WordPress rewrite rules by clicking the "Save Changes" button at WP Admin -> Settings -> Permalinks and then check that permalinks of these pages.
I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar