Skip to content

Instantly share code, notes, and snippets.

@topdown
Created May 28, 2015 21:56
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 topdown/00be97b9c331254a4b41 to your computer and use it in GitHub Desktop.
Save topdown/00be97b9c331254a4b41 to your computer and use it in GitHub Desktop.
WP $wpdb->get_results() Gotcha
// Breaks ORDER BY silently
$sql = $this->wpdb->prepare( "SELECT * FROM $this->table ORDER BY 'id' ASC LIMIT %d OFFSET %d", $limit, $start );
// Works correctly
$sql = $this->wpdb->prepare( "SELECT * FROM $this->table ORDER BY id ASC LIMIT %d OFFSET %d", $limit, $start );
$rows = $this->wpdb->get_results( $sql );
return $rows;
@topdown
Copy link
Author

topdown commented May 28, 2015

Spent a couple hours trying to figure out why ASC and DESC was not changing anything.
No errors, just silently outputs the results without order. Stupid single quote marks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment