javascript - In WordPress how do I pass multiple variables into the URL and retrieve them? -


for reason can retriever first variable, in instance, "product_category" out of url http://localhost/coffeesite/?product_category=coffee&brand=bourbon .

i'm outputting javascript confirm i've set variable, again, coffee alerted, , not brand. i'm using wordpress's 'get_query_var'. see code below:

<?php          echo '<script> product_category = "' . get_query_var('product_category') . '";                         brand = "' . get_query_var('brand') . '";                        alert(product_category);                        alert(brand);              </script>';  ?> 

any appreciated - i'm struggling solve it!

since testing, maybe test php directly? function get_query_var wrapper generic php array $_get. should have these values available @ $_get['product_category'] , $_get['brand']. instead of assuming supposed be, why not check have?

<?php      add_settings_error("var-test", "var-test", implode(", ", array_keys($_get))); ?> 

disclaimer: drupal developer, not wordpress, both php. using documented message tool here, little cleaner php code. https://codex.wordpress.org/function_reference/add_settings_error still use javascript if like:

<?php      echo '<script> alert( '. implode(", ", array_keys($_get)) .');          </script>';  ?> 

second possibility. reason using wrapper function instead of raw core provides in wrap. normal assumption sanitation , security filters, poor testing essential production environments. however, little bit of reading on function using, says returns values known query objects , if using custom variables in url should register them. https://codex.wordpress.org/function_reference/get_query_var have registered "brand"?


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -