select query in wordpress – how to run Select Query in wordpress?

select query in wordpress A beginner’s guide to using SQL to query the WordPress database SELECT query in wordpress with where clause Examples.

Free Live Chat for Any Issue

select query in wordpress

I create a new WordPress query using the WP_Query class using $wpdb->get_results. also WordPress is written using PHP and MySQL.

$post_id = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE (meta_key = 'yiik-new-url123' AND meta_value = '". $from ."')");

Don’t Miss : How To Insert Query In WordPress Using Wpdb?

Display results from a query with PHP (WordPress)

global $wpdb;
$result = $wpdb->get_results('SELECT name, count FROM wp_coomarc_info');
foreach($result as $row) {
    echo 'Name: '.$row->name.', Count: '.$row->count.'<br/>';

Display query custom table on WordPress

global $wpdb;
$result = $wpdb->get_results("SELECT element_value FROM get_all_useful_details WHERE DATE(date) = CURDATE()");
echo "<table border='1'>";
echo "<tr><th>Date</th><th>Schedule</th><th>Large_quota</th><th>Information</th><th>Main type</th><th>Action</th></tr>";

$count = 0;

foreach($result as $get_all_useful_details){

	$new = $get_all_useful_details->element_label;

	if($new == 1){

	    if( $count > 0 )
	        echo "</tr>";

	    echo "<tr>";

	echo "<td>".$get_all_useful_details->element_value."</td>";

echo "</tr>";

echo "</table>";


global $wpdb;
$result_data = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_name = 'yiik-new-url123'");
echo $result_data;

WP Sql query multiple where clause

using WP_User_Query

$params = array (
    'meta_query'    => array(
            'key'   => 'subscriber',
            'value' => 'true',
            'key'   => 'type',
            'value' => 'false',
    'date_query'    => array(
            'after'     => '2022-04-25 00:00:00',
            'inclusive' => true,

$user_query = new WP_User_Query( $params );


I hope you get an idea about select query in wordpress.
I would like to have feedback on my
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.