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:
get_posts()
- Unlike
WP_Query
, the results ofget_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 ofget_posts
don’t forget about settingignore_sticky_posts
andno_found_rows
params appropriately (both are hardcoded inside aget_posts
function with value oftrue
)
- Unlike
wp_get_recent_posts()
- See
get_posts()
- See
get_children()
- Similar to
get_posts()
, but also performs a no-LIMIT query among other bad things by default. Alias ofbreak_my_site_now_please()
. Do not use. Instead do a regular WP_Query and make sure that 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)
- Similar to
term_exists()
- Use
wpcom_vip_term_exists()
instead
- Use
get_page_by_title()
- Use
wpcom_vip_get_page_by_title()
instead
- Use
get_page_by_path()
- Use
wpcom_vip_get_page_by_path()
instead
- Use
url_to_postid()
- Use
wpcom_vip_url_to_postid()
instead
- Use
count_user_posts()
- Use
wpcom_vip_count_user_posts()
instead.
- Use
wp_old_slug_redirect()
- Use
wpcom_vip_old_slug_redirect()
instead.
- Use
get_adjacent_post()
,get_previous_post()
,get_next_post()
,previous_post_link()
,next_post_link()
- Use
wpcom_vip_get_adjacent_post()
instead.
- Use
attachment_url_to_postid()
- Use
wpcom_vip_attachment_url_to_postid()
instead.
- Use
wp_oembed_get()
- Use
wpcom_vip_wp_oembed_get()
instead.
- Use