Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin tommcfarlin/00-keys-to-map.php Secret

Last active Jun 20, 2017
What would you like to do?
[WordPress] WordPress Queries with IN Clauses
// This is used to maintain a map of data should we need to add more.
$data_types = [
* Converts the incoming array into a comma-delimited string with
* quotes wrapped around each key.
* @access private
* @param array $arr The array to convert to a string.
* @return string The string representation of the array delimited by quotes and commas.
private function convert_to_sql_ready_string( $arr ) {
return '"' . implode( $arr, '","' ) . '"';
public function get_data_values() {
global $wpdb;
$query = "
SELECT post_id, meta_key, meta_value
FROM $wpdb->postmeta WHERE
meta_key in ( $this->data_types )
meta_value <> '';
$results = $wpdb->get_results( $query );
return $results;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.