Passing parameter from the current URL to redirect to another url

I have a search results page and on the page, I would like to be able to filter by category. So when the user searches an item, it gets passed to the results page in the url like:

website.com/?s=example

What I would like to do is take the value of "s" and use it in a link to another page.

What I am thinking is doing something like this:

$_searchquery = $_GET['s'];

Then adding the $_searchquery variable to the url I am wanting to redirect to by doing something along these lines:

a href="website.com/?s=?php echo $_searchquery ?category_name=example" Example Category /a

Which in theory will redirect to a search results page that will display the search results for 'example' that appear in the 'example' category. Is this correct?

Topic variables php links Wordpress

Category Web


This worked perfectly for me! The goal was to get a button that would filter my search results by post category and the above solution works exactly how I wanted it to.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.