WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to learn how to run commands through WP rather than SQL commands

I have a SQL command:

(select meta_value from wp_postmeta where meta_key = a 'geo_latitude' AND x.post_id = a.post_id) as lat is NOT NULL,
(select meta_value from wp_postmeta where meta_key = b 'geo_longitude' AND x.post_id = b.post_id) as lon is NOT NULL,
(select meta_value from wp_postmeta where meta_key = c 'address' AND x.post_id = c.post_id) as the address is NOT NULL
FROM elreal_postmeta x group by post_id, lat, lon, address

Can I run this command into the wpdb class?

share|improve this question
up vote 0 down vote accepted

Arbitrary SQL query can be run via wpdb by using get_results() method:

$results = $wpdb->get_results( $query );

You can work through documentation for wpdb at Codex to gain basic understanding of how it works.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.