The difference between $wpdb->query vs. $wpdb->get_results in WordPress

This took me a while to figure out when I started intuitively using $wpdb->query to pull in results from a query in a custom table in WordPress.

However, $wpdb->query only returns the count of the query. You have to use $wpdb->get_results to get the actual SELECT statement back.

Good to know, and will save you some time if you stumble across this trying to figure out why WordPress is returning the count to you rather than the the query results.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s