Ok, I found the problem. It’s in the get_permalink() function in wp-includes/link-template.php. The tag isn’t even considered in constructing the permalink. I fixed it in the code below if you want to replace that function in the file. If you want I can probably post the entire file somewhere (or maybe I should just submit a patch). Anyway, here’s the code…
function get_permalink($id = 0, $leavename = false) {
$rewritecode = array(
'%year%',
'%monthnum%',
'%day%',
'%hour%',
'%minute%',
'%second%',
$leavename? '' : '%postname%',
'%post_id%',
'%category%',
'%author%',
$leavename? '' : '%pagename%',
'%tag%',
);
if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter )
$post = $id;
else
$post = &get_post($id);
if ( empty($post->ID) ) return false;
if ( $post->post_type == 'page' )
return get_page_link($post->ID, $leavename);
elseif ($post->post_type == 'attachment')
return get_attachment_link($post->ID);
$permalink = get_option('permalink_structure');
if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
$unixtime = strtotime($post->post_date);
$category = '';
if ( strpos($permalink, '%category%') !== false ) {
$cats = get_the_category($post->ID);
if ( $cats ) {
usort($cats, '_usort_terms_by_ID'); // order by ID
$category = $cats[0]->slug;
if ( $parent = $cats[0]->parent )
$category = get_category_parents($parent, false, '/', true) . $category;
}
// show default category in permalinks, without
// having to assign it explicitly
if ( empty($category) ) {
$default_category = get_category( get_option( 'default_category' ) );
$category = is_wp_error( $default_category ) ? '' : $default_category->slug;
}
}
$tag = '';
if ( strpos($permalink, '%tag%') !== false ) {
$tags = get_the_tags($post->ID);
if ( $tags ) {
usort($tags, '_usort_terms_by_ID'); // order by ID
$tag = $tags[0]->slug;
}
}
$author = '';
if ( strpos($permalink, '%author%') !== false ) {
$authordata = get_userdata($post->post_author);
$author = $authordata->user_nicename;
}
$date = explode(" ",date('Y m d H i s', $unixtime));
$rewritereplace =
array(
$date[0],
$date[1],
$date[2],
$date[3],
$date[4],
$date[5],
$post->post_name,
$post->ID,
$category,
$author,
$post->post_name,
$tag,
);
$permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
$permalink = user_trailingslashit($permalink, 'single');
return apply_filters('post_link', $permalink, $post, $leavename);
} else { // if they're not using the fancy permalink option
$permalink = get_option('home') . '/?p=' . $post->ID;
return apply_filters('post_link', $permalink, $post, $leavename);
}
}
NOTE: I have not tested whether the permalinks still work if there is no tag for a post. Let me know if you test that out.