2

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' => '/','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?

  • is the phase tax used only by articles post type? – inarilo Dec 29 '17 at 20:33
  • Yes, that is correct :) – Erik van der Bas Jan 10 '18 at 16:29
  • is the above all the code involved in routing? or do you have code redirecting the permalinks? – inarilo Jan 10 '18 at 18:54
  • the same problem here... 404 error appears after setting the permalink stucture. – pendjer Feb 20 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.