Monday, August 15, 2022
HomeWordPress Developmentplugins - Getting URL GET parameter with Code snippets and storing it...

plugins – Getting URL GET parameter with Code snippets and storing it in database?


I have to extract particular parameter utm_medium that’s handed as parameter to all pages or posts on my WP web site and retailer it in database. So each time somebody visits my submit I have to accumulate that parameter and retailer it in some desk in database. First code works however solely first time I go to that exact web page, it shops parameter in desk. Each different time I go to identical web page(submit) with different worth of that parameter it isn’t been saved. This can be a code:

if(isset($_GET['utm_medium'])){
        international $wpdb;
        $tablename = $wpdb->prefix.'take a look at';
        $wpdb->insert($tablename, array(
                                    'utm_medium' =>$_GET['utm_medium'],
            ));
}

It must be Auto Insert not Shortcode, and the code should be run in all places. I’m utilizing WPCode to make PHP snippet with these config of snippets.

enter image description here

I’ve additionally tried this however with no success:

add_action('init','add_get_val');
     operate add_get_val() { 
         international $wp; 
         $wp->add_query_var('utm_medium'); 
     }
    
     if(get_query_var('utm_medium')){
            international $wpdb;
            $tablename = $wpdb->prefix.'take a look at';
            strive{
                $wpdb->insert($tablename, array(
                                        'utm_medium' =>get_query_var('utm_medium')
                ));
            }catch (Exception $e){
            }
     }

Can I exploit this method with WPCode PHP snippet and first code to make it retailer worth each time?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments