wpdb::get_col()
Retrieves one column from the database.
Executes a SQL query and returns the column from the SQL result. If the SQL result contains more than one column, the column specified is returned. If $query is null, the specified column from the previous SQL result is returned.
{} It's a method of the class: wpdb{}
No Hooks.
Return
Array
. Database query result. Array indexed from 0 by SQL result row number.
Usage
global $wpdb; $wpdb->get_col( $query, $x );
- $query(string|null)
- SQL query.
Default: previous query - $x(int)
- Column to return. Indexed from 0.
Changelog
Since 0.71 | Introduced. |
Code of wpdb::get_col() wpdb::get col WP 5.9.3
public function get_col( $query = null, $x = 0 ) { if ( $query ) { if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { $this->check_current_query = false; } $this->query( $query ); } $new_array = array(); // Extract the column values. if ( $this->last_result ) { for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { $new_array[ $i ] = $this->get_var( null, $x, $i ); } } return $new_array; }