Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

I have a SQL command:

SELECT
post_id,
(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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.