How to run mysql query in wordpress?

This query works and returns the results 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 see all the "points" received from user 1. I need to be able to display this on posts and pages in Wordpress.

+4
source share
2 answers
global $wpdb;    
$result = $wpdb->get_results( "SELECT * FROM wp_usermeta WHERE meta_key = 'points' AND user_id = '1'");
print_r($result);

Read this one .

+5
source

Use the following code .....

$q="SELECT * FROM wp_usermeta WHERE meta_key = 'points' AND user_id = '1'";
$result = $wpdb->get_results($q);

As a result, it will return an array.

0
source

All Articles