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