Home > front end >  How do you get wordpress plugin shortcode to $_GET url parameters
How do you get wordpress plugin shortcode to $_GET url parameters

Time:02-02

I have a plugin on a page update-data which has a shortcode on the page of [updatedata]

here is what an update row looks like

  <td><a href="<?php echo admin_url('http://localhost/update-data&id='.$id); ?>">UPDATE</a></td>

Here is what the plugin code is

<?php
/*
plugin name: deano plugin update
description: deano test database to update data into books table
author: Dean-O

*/
$path = preg_replace('/wp-content.*$/', '', __DIR__);
require_once($path.'/wp-load.php');

error_log("here");  // echos to log file
error_log(var_dump($id));  // echos a blank line to the log file
error_log("here 2"); // echos to the log file

function deanoupdatedata($atts, $content = null ) {
$a = shortcode_atts( array(
    'id' => 'id'
), $atts );

return '<a id="' . esc_attr($a['id']) . '</a>';   // never displays
}
add_shortcode('updatedata','deanoupdatedata');


?>

How can I get the url parameter id in the plugin when I click on update link?

CodePudding user response:

Try if($_GET['id']) instead of isset and istead of error_log use var_dump to get the exact value

CodePudding user response:

It is a bad practice. You should pass the data to a shortcode using the shortcode's attributes.

  •  Tags:  
  • Related