wpdb::get_col PHP Method

get_col() public method

Executes a SQL query and returns the column from the SQL result. If the SQL result contains more than one column, this function returns the column specified. If $query is null, this function returns the specified column from the previous SQL result.
Since: 0.71
public get_col ( string | null $query = null, integer $x ) : array
$query string | null Optional. SQL query. Defaults to previous query.
$x integer Optional. Column to return. Indexed from 0.
return array Database query result. Array indexed from 0 by SQL result row number.
    public function get_col($query = null, $x = 0)
    {
        if ($query) {
            $this->query($query);
        }
        $new_array = [];
        // Extract the column values
        for ($i = 0, $j = count($this->last_result); $i < $j; $i++) {
            $new_array[$i] = $this->get_var(null, $x, $i);
        }
        return $new_array;
    }

Usage Example

コード例 #1
0
 /**
  * Deletes all plugin terms.
  *
  * @return void
  */
 private function delete_terms()
 {
     $query = "\nSELECT term_id\nFROM {$this->wpdb->term_taxonomy}\nWHERE taxonomy = %s\nLIMIT 500";
     $query = $this->wpdb->prepare($query, $this->taxonomy);
     while ($term_ids = $this->wpdb->get_col($query)) {
         foreach ($term_ids as $term_id) {
             wp_delete_term($term_id, $this->taxonomy);
         }
     }
 }
All Usage Examples Of wpdb::get_col