0

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?

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.