wp_prime_network_option_caches()wp-includes/option.php | Primes specific network options into the cache with a single database query.
|
wp_prime_option_caches()wp-includes/option.php | Primes specific options into the cache with a single database query.
|
_prime_post_parent_id_caches()wp-includes/post.php | Prime the cache containing the parent ID of various post objects.
|
WP_Site_Health::should_suggest_persistent_object_cache()wp-admin/includes/class-wp-site-health.php | Determines whether to suggest using a persistent object cache.
|
WP_Debug_Data::get_database_size()wp-admin/includes/class-wp-debug-data.php | Fetches the total size of all the database tables for the active database user.
|
wp_is_site_initialized()wp-includes/ms-site.php | Checks whether a site is initialized.
|
WP_Privacy_Requests_Table::get_request_counts()wp-admin/includes/class-wp-privacy-requests-table.php | Counts the number of requests for each status.
|
has_term_meta()wp-includes/taxonomy.php | Gets all meta data, including meta IDs, for the given term ID.
|
WP_Term_Query::get_terms()wp-includes/class-wp-term-query.php | Retrieves the query results.
|
_prime_term_caches()wp-includes/taxonomy.php | Adds any terms from the given IDs to the cache that do not already exist in cache.
|
_prime_network_caches()wp-includes/ms-network.php | Adds any networks from the given IDs to the cache that do not already exist in cache.
|
_prime_site_caches()wp-includes/ms-site.php | Adds any sites from the given IDs to the cache that do not already exist in cache.
|
wxr_term_meta()wp-admin/includes/export.php | Outputs term meta XML tags for a given term object.
|
WP_Term::get_instance()wp-includes/class-wp-term.php | Retrieve WP_Term instance.
|
_prime_comment_caches()wp-includes/comment.php | Adds any comments from the given IDs to the cache that do not already exist in cache.
|
_wp_batch_split_terms()wp-includes/taxonomy.php | Splits a batch of shared taxonomy terms.
|
wpdb::get_table_charset()wp-includes/class-wpdb.php | Retrieves the character set for the given table.
|
maybe_convert_table_to_utf8mb4()wp-admin/includes/upgrade.php | If a table only contains utf8 or utf8mb4 columns, convert it to utf8mb4.
|
attachment_url_to_postid()wp-includes/media.php | Tries to convert an attachment URL into a post ID.
|
check_column()wp-admin/install-helper.php | Checks that database table column matches the criteria.
|
export_date_options()wp-admin/export.php | Creates the date options fields for exporting a given post type.
|
export_wp()wp-admin/includes/export.php | Generates the WXR export file for download.
|
wxr_authors_list()wp-admin/includes/export.php | Outputs list of authors with posts.
|
get_editable_authors()wp-admin/includes/deprecated.php | Gets author users who can edit posts.
|
get_others_unpublished_posts()wp-admin/includes/deprecated.php | Retrieves editable posts from other users.
|
WP_List_Table::months_dropdown()wp-admin/includes/class-wp-list-table.php | Displays a dropdown for filtering items in the list table by month.
|
pre_schema_upgrade()wp-admin/includes/upgrade.php | Runs before the schema is upgraded.
|
upgrade_network()wp-admin/includes/upgrade.php | Executes network-level upgrade routines.
|
get_alloptions_110()wp-admin/includes/upgrade.php | Retrieve all options as it was for 1.2.
|
dbDelta()wp-admin/includes/upgrade.php | Modifies the database based on specified SQL statements.
|
get_users_drafts()wp-admin/includes/user.php | Retrieve the user’s drafts.
|
parent_dropdown()wp-admin/includes/template.php | Prints out option HTML elements for the page parents drop-down.
|
media_upload_library_form()wp-admin/includes/media.php | Outputs the legacy media upload form for the media library.
|
has_meta()wp-admin/includes/post.php | Returns meta data for the given post ID.
|
bulk_edit_posts()wp-admin/includes/post.php | Processes the post data for the bulk editing of posts.
|
WP_Importer::get_imported_comments()wp-admin/includes/class-wp-importer.php | Sets array with imported comments from WordPress database.
|
WP_Importer::get_imported_posts()wp-admin/includes/class-wp-importer.php | Returns array with imported permalinks from WordPress database.
|
WP_Importer::count_imported_posts()wp-admin/includes/class-wp-importer.php | Returns count of imported permalinks from WordPress database.
|
get_pending_comments_num()wp-admin/includes/comment.php | Gets the number of pending comments on a post or posts.
|
cache_users()wp-includes/pluggable.php | Retrieves info for user lists to prevent multiple queries by get_userdata() .
|
wp_get_archives()wp-includes/general-template.php | Displays archive links based on type and format.
|
get_calendar()wp-includes/general-template.php | Displays calendar with days that have posts as links.
|
get_users_of_blog()wp-includes/deprecated.php | Get users for the site.
|
WP_Query::get_posts()wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables.
|
wp_scheduled_delete()wp-includes/functions.php | Permanently deletes comments or posts of any type that have held a status of ‘trash’ for the number of days defined in EMPTY_TRASH_DAYS.
|
is_blog_installed()wp-includes/functions.php | Determines whether WordPress is already installed.
|
_pad_term_counts()wp-includes/taxonomy.php | Adds count of children to parent count.
|
clean_term_cache()wp-includes/taxonomy.php | Removes all of the term IDs from the cache.
|
wp_delete_term()wp-includes/taxonomy.php | Removes a term from the database.
|
wp_version_check()wp-includes/update.php | Checks WordPress version against the newest version.
|
wp_load_alloptions()wp-includes/option.php | Loads and caches all autoloaded options, if available or all options.
|
WP_User_Query::query()wp-includes/class-wp-user-query.php | Executes the query, with the current variables.
|
count_many_users_posts()wp-includes/user.php | Gets the number of posts written by a list of users.
|
wp_enqueue_media()wp-includes/media.php | Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs.
|
_prime_post_caches()wp-includes/post.php | Adds any posts from the given IDs to the cache that do not already exist in cache.
|
get_page_by_path()wp-includes/post.php | Retrieves a page given its path.
|
wp_delete_post()wp-includes/post.php | Trashes or deletes a post or page.
|
wp_trash_post_comments()wp-includes/post.php | Moves comments for a post to the Trash.
|
wp_count_posts()wp-includes/post.php | Counts number of posts of a post type and if user has permissions to view.
|
wp_count_attachments()wp-includes/post.php | Counts number of attachments for the mime type(s).
|
WP_Rewrite::page_uri_index()wp-includes/class-wp-rewrite.php | Retrieves all pages and attachments for pages URIs.
|
redirect_canonical()wp-includes/canonical.php | Redirects incoming links to the proper URL based on the site url.
|
install_blog()wp-includes/ms-deprecated.php | Install an empty blog.
|
get_admin_users_for_domain()wp-includes/ms-deprecated.php | Get the admin for a domain/path combination.
|
get_bookmarks()wp-includes/bookmark.php | Retrieves the list of bookmarks.
|
get_blog_list()wp-includes/ms-deprecated.php | Deprecated functionality to retrieve a list of all sites.
|
wp_list_authors()wp-includes/author-template.php | Lists all the authors of the site, with several options available.
|
get_last_updated()wp-includes/ms-blogs.php | Gets a list of most recently updated blogs.
|
wp_xmlrpc_server::mt_getTrackbackPings()wp-includes/class-wp-xmlrpc-server.php | Retrieves trackbacks sent to a given post.
|
wp_xmlrpc_server::pingback_ping()wp-includes/class-wp-xmlrpc-server.php | Retrieves a pingback and registers it.
|
wp_xmlrpc_server::pingback_extensions_getPingbacks()wp-includes/class-wp-xmlrpc-server.php | Retrieves an array of URLs that pingbacked the given URL.
|
wp_xmlrpc_server::attach_uploads()wp-includes/class-wp-xmlrpc-server.php | Attaches an upload to a post.
|
wp_xmlrpc_server::wp_getPageList()wp-includes/class-wp-xmlrpc-server.php | Retrieves page list.
|
update_meta_cache()wp-includes/meta.php | Updates the metadata cache for the specified objects.
|
Example about how can you retrieve data from a table using get_results function:
Please, note that I have used %d assuming that $some_parameter is a int value.
Don’t forget to handle the error case. Here is how to catch errors from
get_results:When using OBJECT_K, the docs say “Duplicate keys are discarded” but don’t say WHICH row survives. Looking at the source:
foreach ( $this->last_result as $row ) {
$var_by_ref = get_object_vars( $row );
$key = array_shift( $var_by_ref );
if ( ! isset( $new_array[ $key ] ) ) {
$new_array[ $key ] = $row;
}
}
The FIRST row for each key wins, and every later row with the same key is discarded. This is the opposite of how a normal PHP loop assignment behaves ($array[$key] = $value repeated in a loop normally means “last write wins”), so it’s an easy assumption to get backwards.
In practice, this means: if you query something like “the latest meta value per post” or “the newest row per user_id” and rely on OBJECT_K to collapse duplicates, the row you actually get back depends entirely on the order MySQL returns rows in — which is NOT guaranteed unless you explicitly ORDER BY.
// WRONG: assumes the “latest” row wins, but SQL row order isn’t
// guaranteed without ORDER BY, so this can silently return stale data.
$latest_by_post = $wpdb->get_results(
“SELECT post_id, meta_value FROM $wpdb->postmeta
WHERE meta_key = ‘my_key’”,
OBJECT_K
);
// RIGHT: since OBJECT_K keeps the FIRST row per key, order by the
// field that determines “latest” in DESCENDING order, so the row you
// want to keep is the first one MySQL returns for each post_id.
$latest_by_post = $wpdb->get_results(
“SELECT post_id, meta_value FROM $wpdb->postmeta
WHERE meta_key = ‘my_key’
ORDER BY meta_id DESC”,
OBJECT_K
);
If your key column isn’t guaranteed unique in the result set and you don’t care which duplicate wins, this doesn’t matter — but if you do care (e.g. “most recent per group”), always pair OBJECT_K with an explicit ORDER BY, otherwise which row you get is essentially undefined behavior.
The example below is using heredoc to write the query and then getting the result through
$wpdb->get_result(). The second parameterARRAY_Aused on the function will tell to the function that we need the result to be an Array.