I’m trying to add a voting system to my website which uses the CMS WordPress.
I suppose AJAX should be used and I have a template file and an external PHP file which accesses the database, but that obviously doesn’t work well.
I get this error:
“Call to undefined function add_action()”.
$wpdb
probably can’t be used in an external PHP file.
How can I define $wpdb
to be able to use it?
You should use the $wpdb as global variable and you can call it from anywhere in the function.