这是自定义帖子类型的默认链接: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);
1 回答
ITMISS
TA贡献1871条经验 获得超8个赞
function custom_rewrite_tag() {
add_rewrite_tag( '%meta_id%', '([^&]+)' );
}
add_action('init', 'custom_rewrite_tag', 10, 0);
function custom_rewrite_rule() {
add_rewrite_rule('^course/([^/]*)/lesson/([0-9]+)/?','index.php?post_type=course&name=$matches[1]&meta_id=$matches[2]', 'top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
- 1 回答
- 0 关注
- 95 浏览
添加回答
举报
0/150
提交
取消