Title: PHP $_GET vars lost in shortcode
Last modified: March 28, 2023

---

# PHP $_GET vars lost in shortcode

 *  [diafol](https://wordpress.org/support/users/diafol/)
 * (@diafol)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/php-_get-vars-lost-in-shortcode/)
 * Hi, just wanted to say great plugin! However I’ve run into a bit of an issue 
   with a shortcode I created that relies on** $_GET** to get a date querystring
   param from the url to load dynamic data from the DB. I noticed that you mentioned
   in another thread that this plugin doesn’t/can’t support **Code Snippets** (which
   is where I located the code). Easy enough for me to put it in my child theme **
   functions.php** though. Here’s a simplified version of what I’m doing…
 *     ```wp-block-code
       if( isset($_GET['date'] ) && $_GET['date'] ){
           $now = strtotime($_GET['date']);
       }else{
           $now = time();
       }
   
       //print_r( $_GET ); 
       //This now gives: Array ( [action] => eos_dyn_get_content )
   
       //Simplified *unsafe* sql for brevity	
       $sql = "SELECT * FROM mqq_participants_database WHERE UNIX_TIMESTAMP(show_from) <= $now AND UNIX_TIMESTAMP(show_to) >= $now ORDER BY show_from DESC LIMIT 1";
       ```
   
 * As I’m currently testing, it’s not urgent and I will be removing the user-supplied(
   $_GET) date, relying solely on the current time, but possible I’ll be making 
   an interactive section in another page.
 * Wondering if there’s a workaround or if it’s just my rotten luck to have chosen
   Code Snippets?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [diafol](https://wordpress.org/support/users/diafol/)
 * (@diafol)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/php-_get-vars-lost-in-shortcode/#post-16602324)
 * Ok, transferred all code to child theme **functions.php** and had exactly same
   result. Couple o images:
 * [https://pasteboard.co/WKHGc8bIFdNu.png](https://pasteboard.co/WKHGc8bIFdNu.png)
 * [https://pasteboard.co/pd18BHPYJl3x.png](https://pasteboard.co/pd18BHPYJl3x.png)
 *  Thread Starter [diafol](https://wordpress.org/support/users/diafol/)
 * (@diafol)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/php-_get-vars-lost-in-shortcode/#post-16603136)
 * Ah, OK, I think I’ve cracked it. Just add the expected params to the **content-
   no-cache.php** file around line number 111:
 *     ```wp-block-code
       $output .= 'req.open("POST","'.esc_js( admin_url( 'admin-ajax.php' ) ).'?action=eos_dyn_get_content",true);';
       ```
   
 * I got the **$_GET** params to propagate through to my shortcode code.
 *     ```wp-block-code
       $output .= 'req.open("POST","'.esc_js( admin_url( 'admin-ajax.php' ) ).'?action=eos_dyn_get_content&date=' . $_GET['date'] . '&lang=' . $set_lang . '",true);';
       ```
   
 * Obviously there needs to be validation etc before blindly throwing in these vars,
   but it worked for me (date and language successfully passed on). If there’s an
   easier way…?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘PHP $_GET vars lost in shortcode’ is closed to new replies.

 * ![](https://ps.w.org/content-no-cache/assets/icon-256x256.png?rev=2687570)
 * [Content No Cache | Serve uncached partial content even when you add it to a page that is fully cached.](https://wordpress.org/plugins/content-no-cache/)
 * [Support Threads](https://wordpress.org/support/plugin/content-no-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/content-no-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/content-no-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/content-no-cache/reviews/)

## Tags

 * [$_get](https://wordpress.org/support/topic-tag/_get/)

 * 2 replies
 * 1 participant
 * Last reply from: [diafol](https://wordpress.org/support/users/diafol/)
 * Last activity: [3 years, 2 months ago](https://wordpress.org/support/topic/php-_get-vars-lost-in-shortcode/#post-16603136)
 * Status: not resolved