Wordpress - Differences between wpdb->get_results() and wpdb->query()

The difference, if you want to call it that, is that the query() is the most generalized method to do queries with $wpdb, the get_results() method on the other hand is a specific method, which does make use of the query() method to retrieve the specific results of this method and then does some work on the output.


It is the output juggling that get_results() does. If you look at the source for get_results(), the work of the query is done by query(). Eveything after that is just "casting" the results to the data type specified by the $output argument.

1946          public function get_results( $query = null, $output = OBJECT ) {
1947                  $this->func_call = "\$db->get_results(\"$query\", $output)";
1948  
1949                  if ( $query )
1950                          $this->query( $query );
1951                  else
1952                          return null;

Tags:

Query

Wpdb