To handle the extra URL segment you need to add another rewrite rule similar to the one generated by add_permastruct
, but with an extra capture group and slash for the additional level of terms:
add_rewrite_rule(
'book/([^/]+)/([^/]+)/([^/]+)-blah-blah-blah?(:/([0-9]+))?/?$',
'index.php?post_type=book&name=$matches[3]',
'top'
);
Also, as I mentioned in my comment, the query var and slug author
are already in use by core, you should probably change those.
Also in your post_type_link
function, you should check if terms/parent terms exist before trying to access their properties, which will produce warnings with debugging enabled.