dongzz4545 2017-07-27 20:31
浏览 37

WordPress从URL中删除自定义变量

I am appending "?sel" to my URL in order to keep track of which link was selected, and then show items based on that selection in the next page. I used the following in functions.php to register it as a Query var (rather than just use $_GET):

function add_query_vars_filter( $vars ){
  $vars[] = "sel";
  return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );

Then I created the link with the var using add_query_arg() in the template where the links are.

$link = add_query_arg( 'sel', $slug, get_the_permalink($news_specials_listing_page_id) );
<a href="<?php echo $link ?>">

However, if I click that link, I still see the "?sel" in the URL. I've got my permalinks setting to post name in settings > permalinks, so I don't see the typical WordPress variables. Is it posible to hide "sel" along with the rest of the registered query variables, and still grab the value using get_query_var()?

I have also tried adding a custom rewrite tag and flushing my permalinks.

function custom_rewrite_tag() {
    add_rewrite_tag('%sel%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);

I have been experimenting with add_rewrite_rule() and have found that it adds RewriteRules to .htaccess. So if I add a rewrite rule that captures the sel variable in a regular expression and redirect it, would the variable still get saved? I'm also having a difficult time figuring out what the rule would be.

</div>
  • 写回答

1条回答 默认 最新

  • douzhulan1815 2017-07-27 21:59
    关注

    The whole point of using GET is to put variables into your URL. This forms a unique URL that can be bookmarked and indexed by search engines. If you do not want to do this use POST instead. POST allows you to encrypt variable names making it far more secure than the solution you are asking about.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端