Skip to content

Instantly share code, notes, and snippets.

@alexphelps
Last active December 18, 2015 04:23
Show Gist options
  • Save alexphelps/ba501813b9b32598d8a9 to your computer and use it in GitHub Desktop.
Save alexphelps/ba501813b9b32598d8a9 to your computer and use it in GitHub Desktop.
Wordpress Query with Prepare
<?php
/**
* SQL query using $wpdb->prepare to protect it from sql injection
*/
private function get_users_pending( $user_id ) {
global $wpdb;
$the_post_type = 'post';
$status = 'pending';
return $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = %s AND post_status = %s AND post_author = %s ORDER BY post_modified DESC", $the_post_type, $status, $user_id ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment