WordPress

How To Get Data Through SQL Query In WordPress

In this article we will see how to get data from database using SQL Query in WordPress.

We are going to use get_results() function to execute the query.

$table_name = 'wp_users';
$results = $wpdb->get_results( " SELECT * FROM $table_name " );
echo "<pre>";
print_r($results);
echo "</pre>";

Here in the above example I have gotten data of wp_users table using get_results function.

You can see I have used $wpdb variable.

$wpdp is a database access abstraction class.

Here I have added code and I even haven’t define $dpdb but still I am getting the results because I have added this code in my theme’s function file.

If you will not able to access the $wpdb then you need to assign this as global $wpdb;

If you have any difficulty you can reach out to me through comment.

Thank you.

Selina Parmar

I am a senior WordPress Developer at Vision Infotech. I have expertise in Web Designing and Development with PHP WordPress. I have enough skills in HTML, CSS, Bootstrap, JavaScript, jQuery, SQL, Web API. Also additionally I can do integration of the Zoho Platform using deluge code.

Share
Published by
Selina Parmar

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago