admin管理员组文章数量:1122826
I have studied in detail the rules for creating permalinks for custom post types and have been using them successfully.
But I had a task to create permanent links for the album
type based on the post format, i.e. for example, for a post_format=gallery
the link should be
/photogallery/album/%post_name%
,
and for a video
it should be
/video/item/%post_name%
I am using the following code
add_filter('post_type_link', 'videos_postformat_permalink', 10, 4);
function videos_postformat_permalink($post_link, $post, $leavename, $sample)
{
if ('album' == $post->post_type){
if ( false !== strpos( $post_link, 'photogallery/album' ) ) {
if ('video' == get_post_format($post->ID)){
$post_link = str_replace( 'photogallery/album', 'video/item', $post_link );
}
}
}
return $post_link;
}
/* and rewrite url */
add_action( 'init', function() {
add_rewrite_rule( 'video/item/([0-9]{5,})/?$', 'index.php?name=$matches[1]', 'top' );
}, 90);
but it doesn't seem to work.
I see well-formed video links on the front of the site, but when I click on them I get a 404 error.
Tell me what did I miss?
本文标签: Custom permalinks for post formats
版权声明:本文标题:Custom permalinks for post formats 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736302141a1931429.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论