On this page
wpdb::get_col( string|null $query = null, int $x ): array
Retrieves one column from the database.
Description
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.
Parameters
$querystring|null Optional-
SQL query. Defaults to previous query.
Default:
null $xint Optional-
Column to return. Indexed from 0.
Return
array Database query result. Array indexed from 0 by SQL result row number.
Source
File: wp-includes/class-wpdb.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| wpdb::check_safe_collation() wp-includes/class-wpdb.php | Checks if the query is accessing a collation considered safe on the current version of MySQL. |
| wpdb::query() wp-includes/class-wpdb.php | Performs a database query, using current database connection. |
| wpdb::get_var() wp-includes/class-wpdb.php | Retrieves one variable from the database. |
Used By
| Used By | Description |
|---|---|
| _wp_batch_update_comment_type() wp-includes/comment.php | Updates the comment type for a batch of comments. |
| wp_delete_site() wp-includes/ms-site.php | Deletes a site from the database. |
| WP_Network_Query::get_network_ids() wp-includes/class-wp-network-query.php | Used internally to get a list of network IDs matching the query vars. |
| WP_Site_Query::get_site_ids() wp-includes/class-wp-site-query.php | Used internally to get a list of site IDs matching the query vars. |
| wp_get_users_with_no_role() wp-includes/user.php | Gets the user IDs of all users with no role on this site. |
| WP_Comment_Query::get_comment_ids() wp-includes/class-wp-comment-query.php | Used internally to get a list of comment IDs matching the query vars. |
| maybe_drop_column() wp-admin/install-helper.php | Drops column from database table, if it exists. |
| export_wp() wp-admin/includes/export.php | Generates the WXR export file for download. |
| WP_User_Search::query() wp-admin/includes/deprecated.php | Executes the user search query. |
| get_author_user_ids() wp-admin/includes/deprecated.php | Get all user IDs. |
| get_editable_user_ids() wp-admin/includes/deprecated.php | Gets the IDs of any users who can edit posts. |
| get_nonauthor_user_ids() wp-admin/includes/deprecated.php | Gets all users who are not authors. |
| wpmu_delete_user() wp-admin/includes/ms.php | Delete a user from the network and remove from all sites. |
| populate_options() wp-admin/includes/schema.php | Create WordPress options and set the default values. |
| maybe_create_table() wp-admin/includes/upgrade.php | Creates a table in the database, if it doesn’t already exist. |
| maybe_add_column() wp-admin/includes/upgrade.php | Adds column to a database table, if it doesn’t already exist. |
| wp_delete_user() wp-admin/includes/user.php | Remove user and optionally reassign posts and links to another user. |
| meta_form() wp-admin/includes/template.php | Prints the form in the Custom Fields meta box. |
| WP_MS_Sites_List_Table::prepare_items() wp-admin/includes/class-wp-ms-sites-list-table.php | Prepares the list of sites for display. |
| get_meta_keys() wp-admin/includes/post.php | Returns a list of previously defined keys. |
| get_available_post_mime_types() wp-includes/post.php | Gets all available post MIME types for a given post type. |
| _wp_delete_orphaned_draft_menu_items() wp-admin/includes/nav-menu.php | Deletes orphaned draft menu items |
| get_usermeta() wp-includes/deprecated.php | Retrieve user metadata. |
| WP_Query::get_posts() wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. |
| do_enclose() wp-includes/functions.php | Checks content for video and audio links to add as enclosures. |
| wp_set_object_terms() wp-includes/taxonomy.php | Creates term and taxonomy relationships. |
| wp_delete_term() wp-includes/taxonomy.php | Removes a term from the database. |
| get_objects_in_term() wp-includes/taxonomy.php | Retrieves object IDs of valid taxonomy and term. |
| WP_User_Query::query() wp-includes/class-wp-user-query.php | Executes the query, with the current variables. |
| count_users() wp-includes/user.php | Counts number of users who have each of the user roles. |
| wp_delete_auto_drafts() wp-includes/post.php | Deletes auto-drafts for new posts that are > 7 days old. |
| wp_delete_attachment() wp-includes/post.php | Trashes or deletes an attachment. |
| get_all_page_ids() wp-includes/post.php | Gets a list of page IDs. |
| wp_delete_post() wp-includes/post.php | Trashes or deletes a post or page. |
| remove_user_from_blog() wp-includes/ms-functions.php | Removes a user from a blog. |
| is_multi_author() wp-includes/author-template.php | Determines whether this site has more than one author. |
| wp_delete_comment() wp-includes/comment.php | Trashes or deletes a comment. |
| delete_metadata() wp-includes/meta.php | Deletes metadata for the specified object. |
| update_metadata() wp-includes/meta.php | Updates metadata for the specified object. If no value already exists for the specified object ID and metadata key, the metadata will be added. |
Changelog
| Version | Description |
|---|---|
| 0.71 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wpdb/get_col