用永久链接中的元数据值替换wordpress slug标题

问题描述 投票:0回答:1

我有一个自定义的帖子类型,没有标题的会议记录。我希望固定链接类似于www.website.com/minutes/2018-10-16/,女巫分钟是注册的自定义帖子类型名称,而2018-10-16是metabox会议日期(我已创建) )。我可以这样做吗?谢谢!

wordpress custom-post-type meta-boxes
1个回答
0
投票

我按照this tutorial找到了解决方案。

这是Milo发布的名为“product”的自定义帖子类型的代码:

add_filter('post_type_link', 'wpse33551_post_type_link', 1, 3);

function wpse33551_post_type_link( $link, $post = 0 ){
    if ( $post->post_type == 'product' ){
        return home_url( 'product/' . $post->ID );
    } else {
        return $link;
    }
}

add_action( 'init', 'wpse33551_rewrites_init' );

function wpse33551_rewrites_init(){
    add_rewrite_rule(
        'product/([0-9]+)?$',
        'index.php?post_type=product&p=$matches[1]',
        'top' );
}
© www.soinside.com 2019 - 2024. All rights reserved.