这是自定义帖子类型的默认链接:
domain.com/course/mern-stack-front-to-back-full-stack-react-redux-node-js
如果存在的参数是 meta_id,我正在尝试创建自定义重写规则
domain.com/course/mern-stack-front-to-back-full-stack-react-redux-node-js?meta_id=1234
应该变成这样:
domain.com/course/mern-stack-front-to-back-full-stack-react-redux-node-js/lesson/1234
这是我在 functions.php 中的代码
function custom_rewrite_tag() {
add_rewrite_tag( '%meta_id%', '([^&]+)' );
}
add_action('init', 'custom_rewrite_tag', 10, 0);
function custom_rewrite_rule() {
add_rewrite_rule( '^lesson/([0-9]+)/?', 'index.php?post_type=course&meta_id=$matches[1]', 'top' );
}
add_action('init', 'custom_rewrite_rule', 10, 0);
ITMISS