S
S
sergo5732021-07-30 16:03:30
PHP
sergo573, 2021-07-30 16:03:30

How to hide the end of a link in the address bar?

Good day everyone!
There is a post filter made in php in wordpress:

<?php

if ($_GET['select'] == 'a1') { $order = "&orderby=views&order=DESC"; $s1 = ' selected="selected"'; }
if ($_GET['select'] == 'a2') { $order = "&orderby=date&order=DESC"; $s2 = ' selected="selected"'; }
?>
<form method="get" id="order">
<select name="select" onchange='this.form.submit()' class="sort">
<option value="a1"<?=$s1?>>По популярности</option>
<option value="a2"<?=$s2?>>По дате</option>
</select>
</form>

<?php global $query_string;
query_posts($query_string.'&'.$order);
?>


After choosing a specific sort, at the end of the link in the address bar there is an inscription:
?select=a1

Tell me how to get rid of it? Or is it impossible without AJAX?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sl0, 2021-07-30
@sergo573

Change in the get form to post.
Well, respectively, in checking $_GET for $_POST.

K
ksnk, 2021-07-30
@ksnk

You probably do not need to hide the end of the address bar, but throw out the already unnecessary select parameter?
Something like that, if query_string is really query_string, and not something else

$query=[];
parse_str(parse_url($query_string, PHP_URL_QUERY),$query_array);
unset($query_array['select']);
echo (!empty($query_array)?'?':'').http_build_query($query_array);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question