Help please. I don't understand this problem.
For a theater website, I have created 2 CPTS : "show" and "event" (/show and /event)
I have created 2 common taxonomies for those CPTS : "season"(ex : 22-23) and "type" (ex: opera)
Why? Because I would like to have these custom URLS at the end : website.com/season/{season}/{type}/show-slug/ (I prefer to remove the base key "show" and "event")
I have write this filter for custom taxonomy :
function wpa_show_permalinks( $post_link, $post ){
if ( is_object( $post ) && ( $post->post_type == 'show' || $post->post_type == 'event') ){
$terms_season= wp_get_object_terms( $post->ID, 'season' );
$terms_type = wp_get_object_terms( $post->ID, 'type' );
if( $terms_season && $terms_type){
return str_replace( '%type%' , $terms_type[0]->slug , str_replace( '%season%' , $terms_season[0]->slug , $post_link ) );
}
}
return $post_link;
}
add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 );
With "custom post type UI" plugin, I have inserted this rewrite rule for my two CPTS :
season/%season%/%type%
THE PROBLEM :
It seems to be a conflict between the 2 CPTs. Only one CPT is accessible by URL, not the other (error 404), especially the "event" post type.
If I remove the rewrite rule for "event", no problem it works. The URL rewriting is working fine, the "%%" URLs are correctly replaced by the filter and written correctly.
But when I click on a "event" post card, the page is blank and the body contains "error404". There is no problem with the "show" post type.
I have tested to change "event" hierarchy with "true" >>> The event works fine, but not the shows (404).
What's going on ???