我正在尝试将查询变量存储到插件前端的本地化变量中。rpSearch以应有的方式显示,但page和share\\u id为;0“;和"E;当我用Monkeyman重写分析器测试url时,它看起来应该会提供我需要的数据
function rewrite() {
add_rewrite_rule(\'^reseplanerare/dela/([^/]+)/?$\',\'index.php?pagename=reseplanerare&page=share&share_id=$matches[1]\', \'top\');
add_rewrite_rule(\'^reseplanerare/planera/([^/]+)/?$\', \'index.php?pagename=reseplanerare&page=plan\', \'top\');
}
function register_query_vars( $vars ) {
$vars[] = \'page\';
$vars[] = \'share_id\';
return $vars;
}
function public_enqueue_scripts() {
global $wp_query;
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . \'js/public/main.js#module\', array(\'jquery\'), $this->plugin_ver,true);
wp_localize_script( $this->plugin_name, \'rpSearch\', array(
\'page\' => urldecode($wp_query->query_vars[\'page\']),
\'share_id\' => urldecode($wp_query->query_vars[\'share_id\'])
));
}
SO网友:FroboZ
在重写规则中,我没有正确链接到页面。pagename的使用不正确,我应该使用page\\u id。我最终使用的重写规则是
add_rewrite_rule(\'^resa/start/?$\', \'index.php?page_id=1897&route_page=start\', \'top\');
add_rewrite_rule(\'^resa/planera/?$\', \'index.php?page_id=1897&route_page=plan\', \'top\');
add_rewrite_rule(\'^resa/dela/([^/]+)/?$\',\'index.php?page_id=1897&route_page=share&share_id=$matches[1]\', \'top\');