Reputation: 1336
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.
Upvotes: 0
Views: 629
Reputation: 1103
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.
Upvotes: 1