5

Who can explain me the differences between wpdb->get_results() and wpdb->query() in making generic queries to wordpress db?

4

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.

5

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.