Skip to content

Instantly share code, notes, and snippets.

@aprea
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aprea/eae346874f39bd8d450d to your computer and use it in GitHub Desktop.
Save aprea/eae346874f39bd8d450d to your computer and use it in GitHub Desktop.
SQL in PHP
<?php
/**
* Get the table data
*
* @return Array
*/
private function table_data() {
global $wpdb;
$sql = <<<SQL
SELECT wp_posts.ID,
m1.meta_value AS email,
wp_posts.post_date_gmt AS date
FROM wp_posts
INNER JOIN wp_postmeta m1 ON ( wp_posts.ID = m1.post_id )
WHERE wp_posts.post_type = 'subscriber'
AND wp_posts.post_status = 'publish'
AND m1.meta_key = 'eec_email'
GROUP BY wp_posts.ID
SQL;
$sql = str_replace( 'wp_', $wpdb->prefix, $sql );
$results = $wpdb->get_results( $sql, ARRAY_A );
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment