Created
May 28, 2015 21:56
-
-
Save topdown/00be97b9c331254a4b41 to your computer and use it in GitHub Desktop.
WP $wpdb->get_results() Gotcha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!