Do you have an example of a single post in this post type that is working, as compared to what you’re aiming for?
My guess at the moment is that the taxonomy isn’t being included in the single post url like you’re wanting. However, what you’re sounding like you are aiming for looks more like it’s interpreting “test” as a taxonomy term and not a post type slug as well.
Thread Starter
rjrp
(@rjrp)
The url now it’s http://odgarchitects.flywheelsites.com/cat/test/
cat – is a category
test – post
I was able to make it work using the code below and adding %project_category% on the rewrite field on the CPT, just wondering if could get to that just using the plugin
function write_projects_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == 'projects' ){
$terms = wp_get_object_terms( $post->ID, 'project_category' );
if( $terms ){
return str_replace( '%project_category%' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( 'post_type_link', 'write_projects_permalinks', 1, 2 );
We do have the “rewrite slug” option available, but beyond that, I probably would have suggested a similar solution to what you already found. CPTUI doesn’t do anything in the areas of permalink customization, outside what to use as the slugs for post types and taxonomies.
Thread Starter
rjrp
(@rjrp)
So I am doing it the right way, there is no way to do this just with the plugin and the rewrite field?
Thanks for all your support.
Yes, I believe so.
A “just in case” thought, if the post has multiple categories, then what you have above will only utilize the first category term found.
Thread Starter
rjrp
(@rjrp)
Posted almost exactly at the same time as me.
You’re on the more right path, though it needs some tweaking. It’s still details we don’t cover with CPTUI itself, and external code is needed. CPTUI handles the registration, hopefully really well for peoples needs, but not much beyond that.
Thread Starter
rjrp
(@rjrp)
Thanks Michael for your support!