This query works and returns the results that I want in MySQL but how do I get this to work in wordpress?
SELECT * FROM `wp_usermeta` WHERE `meta_key` = 'points' AND `user_id` = '1'
I want to be able to see all the 'points' earned by user 1. I need to be able to display this on posts and pages in wordpress.
You should try following code : global $wpdb; $result = $wpdb->get_results( "SELECT * FROM ". $wpdb->prefix."_usermeta WHERE meta_key = 'points' AND user_id = '1'"); print_r($result); Hope it will helpful.
Using MySQL for WordPress MySQL uses table structures to store data. Most web hosts come with a MySQL user interface software called phpMyAdmin. This free and open-source piece of software makes it easy to run database commands.
You can execute a MySQL query towards a given database by opening the database with phpMyAdmin and then clicking on the SQL tab. A new page will load, where you can provide the desired query. When ready click on Go to perform the execution. The page will refresh and you will see the results from the query you provided.
Click on the button on the left panel labeled 'Go to LPCP'. Go to MySQL Manager. Add the user name and database name but leave the host name as the default IP number. Note the IP address of the database on the right which is different from the default IP number of the host indicated in the above step.
global $wpdb;
$result = $wpdb->get_results( "SELECT * FROM wp_usermeta WHERE meta_key = 'points' AND user_id = '1'");
print_r($result);
Read this.
Use following code.....
$q="SELECT * FROM wp_usermeta WHERE meta_key = 'points' AND user_id = '1'";
$result = $wpdb->get_results($q);
It will return array as result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With