0

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?

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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