I am using the below code in functions.php to add custom query variables to my WordPress project.
<?php
function add_custom_query_var( $vars ){
$vars[] = "brand";
return $vars;
}
add_filter( 'query_vars', 'add_custom_query_var' );
?>
And then on the content page I am using:
<?php echo $currentbrand = get_query_var('brand'); ?>
So now I can pass a URL like:
http://myexamplesite.com/store/?brand=nike
and get nike in result.
How can I pass multiple values for a brand. So I would like to have 3 values for brand say, nike, adidas and woodland.
I have tried the following and none of them works:
http://myexamplesite.com/store/?brand=nike&brand=adidas&brand=woodland It just returns the last brand, in this case woodland.
http://myexamplesite.com/store/?brand=nike+adidas+woodland This returns all three with spaces. I kind of think this is not the correct solution. So may be there is a correct way to pass multiple values for a query variable and retrieve them in an array may be so that a loop can be run.