I am having difficulties setting up the following structure in WordPress:

  1. site.com/custom-taxonomy-phase-term/ (taxonomy page but without the taxonomy slug)
  2. site.com/custom-taxonomy-phase-term/article-name/ (single post without the custom post type slug)
  3. site.com/anyotherpage (just displays the page via index.php)

The first two steps are currently working. The only thing is that pages and posts are both giving 404 errors. If I add a custom slug to both the custom tax and custom post, the pages and posts start working again. But I really would like to remove both the tax and custom post slug without breaking the page URL’s.

The following code makes the first two steps possible:

in my custom post type “articles”:

'rewrite' => array('slug' => '%phase%')

in my custom taxonomy “phase”:

'rewrite' => array('slug' => "https://wordpress.stackexchange.com/",'with_front' => false)

in my functions:

function rewrite_article_link( $post_link, $id = 0 ){
    $post = get_post($id);
   if ( is_object( $post ) ){
       $terms = wp_get_object_terms( $post->ID, 'phase' );
        if( $terms ){
            return str_replace( '%phase%' , $terms[0]->slug , $post_link      );
        }
   }
   return $post_link;
}
add_filter( 'post_type_link', 'rewrite_article_link', 1, 3 );

Does anyone has an idea how I could get this structure as mentioned above working?

0

Leave a Reply

Your email address will not be published. Required fields are marked *