-2

In WordPress documentation, it says:

(https://codex.wordpress.org/Class_Reference/wpdb)

SELECT a Variable The get_var function returns a single variable from the database. Though only one variable is returned, the entire result of the query is cached for later use. Returns NULL if no result is found.

get_var( 'query', column_offset, row_offset ); ?>

query (string) The query you wish to run. Setting this parameter to null will return the specified variable from the cached results of the previous query. column_offset (integer) The desired column (0 being the first). Defaults to 0. row_offset (integer) The desired row (0 being the first). Defaults to 0.

My query is, can you please explain this line:

Setting this parameter to null will return the specified variable from the cached results of the previous query.

Which variable? If i code:

<?php $wpdb->get_var( null, column_offset, row_offset ); ?> 

Which variables value is it talking about?

Thanks.

1

You must specify values for column_offset and row_offset. For example:

 <?php $wpdb->get_var( null, 5, 0 ); ?> 

Will return "Hello World" (see attached image) But for that to work you had to have a previous query like this:

 <?php $wpdb->get_var( "SELECT * FROM $wpdb->posts" ); ?> 

result set from previous query

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.