Search code examples
phpwordpressurlquery-stringparse-url

wordpress php get queries from URL


I am making a plugin for wordpress that is located at companyname.com/event/countdown/. On this page I would like to dynamically some information from the url string to show a countdown the company can email. So in the url companyname.com/event/countdown/?city?daysleft how can I echo out the city and the days left separately? So on the page it would be:

Event at <?php echo city ?> is <?php echo daysleft ?> days away

I have seen parse_url and $_SERVER['QUERY_STRING'] but I guess I am not fully sure how to get separate parts or build the url.


Solution

  • Wordpress doesn't stop the usage of typical super globals.

    In this case, you can just use $_GET['city'] and $_GET['daysleft']. The query string should be well formed, unlike yours, observe:

    /?city=mycity&daysleft=someinteger