Is It possible to pass dynamic data to PHP Array generated table?
I'd like to create a PHP file and put in it a WP_query where a parameter is related to the user that is visiting the page or It depends from the page that Is showing the table.
- Please check out this documentation page with a general example of how the serialized PHP array can be used to create tables;
;
Then, to achieve what you described, there is a hook available in the Premium version of the plugin ( the Lite version doesn't have that functionality):
You need to add one more hook to filter the URL of the PHP file.
In file wp-content/plugins/wpdatatables/source/class.wpdatatable.php: around line 1875
function test ($url,$id) {
// all data from current user
// you can fetch only what you need
$userData = wp_get_current_user()->data; if(isset($userData)){
$url .= '?' . http_build_query($userData);
}
return $url;
}
add_filter('wpdatatables_filter_url_php_array', 'test', 2 , 10
In the PHP file, you will use the $_GET method to take the values from the URL which is filtered with the hook
// you can check then for ID or user_login or user_pass or user_nicename or user_email ...
if(isset($_GET['user_login'])){
//do somthing
}
I try to be detailed as I can so you can do this very easily.
Let me know is it working as you need, or if anything wasn't clear enough. Thanks.
In this way, every time the plugin updates, I have to edit the line 1875 in file wp-content/plugins/wpdatatables/source/class.wpdatatable.php, don't I?
Hi.
Is It possible to pass dynamic data to PHP Array generated table?
I'd like to create a PHP file and put in it a WP_query where a parameter is related to the user that is visiting the page or It depends from the page that Is showing the table.
Any way to achieve that?
Hi, Massimiliano
Thanks for reaching out to us
- Please check out this documentation page with a general example of how the serialized PHP array can be used to create tables;
;
Then, to achieve what you described, there is a hook available in the Premium version of the plugin ( the Lite version doesn't have that functionality):
You need to add one more hook to filter the URL of the PHP file.
In file wp-content/plugins/wpdatatables/source/class.wpdatatable.php: around line 1875
you will find this
and under it add this
so it looks like this
In hook, you will do something like this
In the PHP file, you will use the $_GET method to take the values from the URL which is filtered with the hook
I try to be detailed as I can so you can do this very easily.
Let me know is it working as you need, or if anything wasn't clear enough. Thanks.
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Ok, quite clear.
I already have the pro version of the plugin.
In this way, every time the plugin updates, I have to edit the line 1875 in file wp-content/plugins/wpdatatables/source/class.wpdatatable.php, don't I?
My apologies, Massimiliano.
The developers actually already added the hook in the PHP file, it is in the latest version,
the original information I have you was not up-to-date.
- So basically, you won't have to change the code of the plugin, rather just implement the hook with the logic you need, that should do the trick.
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables