0

I'm working on a website, that showcases products, and now I'm working on the query part. Basically I want to have one page, that displays a list of products as a normal query, and then on top of the page I want to have a few buttons as option to sort by name, price, and a dropdown with the taxonomies like brands and stuff. I can make a query display the information as I want, but I can´t combine all these thing I want in one page, because PHP can´t track when a button is clicked and then work with if statements and I'm not an expert, I can't move much further. Is there a way to do what I want the simple way? Wihtout java or ajax... I just want a page that loads with a standard query (I did that) and then when somone click the button Sort something the page reloads and another query is activated.

Thanks in advance, after hours of research this is my last push to get a solution.

1 Answer 1

0

You can use either GET or POST requests to achieve that functionality without using any AJAX (which, in fact, does the same but uses JS to process requests).

You need to add ?name_of_var=value after trailing slash on labels that link to different queries. Basically, your 'Coca-Cola' link has to look this way: site.com/products/?brand=cocacola

After that, let's look into your queries' code. Set your query variables beforehand, checking for needed ones in $_GET array. Here's little example so you could understand what I am talking about:

$brand = ( isset($_GET['brand']) ) ? $_GET['brand'] : 'post'; // We do this because post type can't be defined as null in WordPress, change it according to your query arguments.
$query_args = array ( 'post_type' => array( $brand ) );
$your_custom_query = new WP_Query( $query_args );

Your Answer

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

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