這是自定義帖子類型的默認(rèn)鏈接:domain.com/course/mern-stack-front-to-back-full-stack-react-redux-node-js如果存在的參數(shù)是 meta_id,我正在嘗試創(chuàng)建自定義重寫規(guī)則domain.com/course/mern-stack-front-to-back-full-stack-react-redux-node-js?meta_id=1234應(yīng)該變成這樣: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貢獻(xiàn)1871條經(jīng)驗 獲得超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 關(guān)注
- 131 瀏覽
添加回答
舉報
0/150
提交
取消