I think I am probably missing something very basic here… I am using the following filter to change the format of the permalink to include a custom taxonomy:

Function wpse_56769_post_link( $permalink, $post ) {

    $default_term = 'previews';
    $terms = wp_get_post_terms( $post->ID, 'SBID' );
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) )
        $term = current( $terms )->slug;
    else
        $term = $default_term;

    $permalink = str_replace( '%SBID%', $term, $permalink );

    return $permalink;
}
add_filter( 'post_link', 'wpse_56769_post_link', 10, 2 );

This works so that www.example.com/sb%SBID%.html links to a page that is www.example.com/sbWHATEVER.html. However, it doesnt work if I change %SBID% to %SBIE% e.g.

  $permalink = str_replace( '%SBIE%', $term, $permalink );

www.example.com/sb%SBIE%.html creates the same permalink but I get an 404 error. I have also tried redefining $term and using a different taxonomy and they throw a 404 too. Any idea why this would be? I completely at a loss – why would only this exact configuration work?

I have tried flush_rewrite_rules();

EDIT: Maybe it is relevant that in the single case that it works, for reasons unknown, it shows archive.php rather than single.php.

0

Tags:

Leave a Reply

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