Skip to content

How-to Guides

Technical References

Caching /

Uncached functions

WordPress core has a number of functions that, for various reasons, are uncached, which means that calling them will always result in an SQL query. Below, we outline some of these functions and their VIP cached alternatives.

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.

$args = array(
    'post_type'        => 'post',
    'posts_per_page'   => 3,
    'suppress_filters' => false,
);
$query = get_posts( $args );

When using WP_Query instead of get_posts don’t forget about setting ignore_sticky_posts and no_found_rows params appropriately (both are hardcoded inside a get_posts function with value of true ).

wp_get_recent_posts()

See get_posts() .

get_children()

This is similar to get_posts(), but also performs a no-LIMIT query among other bad things by default. Also known as an alias of break_my_site_now_please(). We highly recommend you do not use it. Instead, do a regular WP_Query and make sure the post_parent you are looking for is not 0 or a falsey value. Also make sure to set a reasonable posts_per_page; get_children will do a -1 query by default. A maximum of 100 should be used, but a smaller value could increase performance.

term_exists()

Use wpcom_vip_term_exists() instead.

get_page_by_title()

Use wpcom_vip_get_page_by_title() instead.

get_page_by_path()

Use wpcom_vip_get_page_by_path() instead.

url_to_postid()

Use wpcom_vip_url_to_postid() instead.

count_user_posts()

Use wpcom_vip_count_user_posts() instead.

wp_old_slug_redirect()

Use wpcom_vip_old_slug_redirect() instead.

get_adjacent_post(), get_previous_post(), get_next_post(), previous_post_link(), next_post_link()

Use wpcom_vip_get_adjacent_post() instead.

attachment_url_to_postid()

Use wpcom_vip_attachment_url_to_postid() instead.

wp_oembed_get()

Use wpcom_vip_wp_oembed_get() instead.

Last updated: November 12, 2020