Changing Custom Permalink with Filter

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;
        $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 links to a page that is However, it doesnt work if I change %SBID% to %SBIE% e.g.

  $permalink = str_replace( '%SBIE%', $term, $permalink ); 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.

Solutions Collecting From Web of "Changing Custom Permalink with Filter"