• 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…

    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

    (@diafol)

    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/pd18BHPYJl3x.png

    Thread Starter diafol

    (@diafol)

    Ah, OK, I think I’ve cracked it. Just add the expected params to the content-no-cache.php file around line number 111:

    $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.

    $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.