I am trying to make ajax in wordpress.
The php file is placed in plugins folder as a plugin
wp-content/ plugins/ my_plugin/ php-file.php
I know that Ajax receives informations from the php file because I did some tests, so the url in ajax is correct !
But when I want to pull some data from the database, I get this error in log file:
PHP Fatal error: Uncaught Error: Call to a member function get_results() on null in /home/......
I specify that I have an error 500 in the browser console (network tab)
my code :
global $wpdb;
$table_name = $wpdb->prefix . "wplusersprofiles";
$user = $wpdb->get_results('SELECT * FROM my_table');
$live_Str = $user[0]->etat;
the problem is therefore is on line 3