Skip to content

Uncached functions

For various reasons, some functions in WordPress core are purposely uncached. Because of this, calling those uncached functions in application code will always result in an SQL query. This can have performance implications for a site, particularly if an uncached function is called by code during a high traffic event. A large volume of direct SQL queries can overload the primary database and lead to an increase in responses with a 503 HTTP status code.

Cached VIP alternative functions

To prevent issues caused by uncached functions, VIP MU plugins provides several alternative versions of functions that will be cached when called on the VIP Platform.

Use wpcom_vip_attachment_url_to_postid() as the cached VIP alternative to:

Use wpcom_vip_count_user_posts() as the cached VIP alternative to:

Use wpcom_vip_get_adjacent_post() as the cached VIP alternative to:

Use wpcom_vip_wp_oembed_get() as the cached VIP alternative to:

Previously uncached WordPress core functions

One of the performance improvements released in WordPress v6.1 was the addition of caching for some database query functions. In all versions of WordPress less than v6.1, the functions listed below are uncached.

  • get_children(): This function is similar to get_posts() and in fact, calls get_posts(). The problem with this query is that by default, it will run a no-LIMIT query and set suppress_filters to true. This will bypass VIP’s query caching and cause unintended performance consequences if a post has too many children. To avoid this, use WP_Query instead and follow these guidelines:
    • Do not set the post_parent to 0 or a false value. Those settings would request every post on the site.
    • Set the posts_per_page to the absolute minimum requirement, and no higher than 100. The lower a value is set for posts_per_page, the better performance can be expected.
  • get_posts(): Unlike WP_Query, the results of get_posts() are not cached via Advanced Post Cache.
    • Use WP_Query instead, or set 'suppress_filters' => false.
    • When using WP_Query instead of get_posts, remember to set ignore_sticky_posts and no_found_rows parameters. Both are hardcoded inside of a get_posts function with the value of true.

Last updated: November 22, 2022