8

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

0

2 Answers 2

5

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.

6

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;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.