Skip to content

Optimize database queries

The WordPress VIP Platform provides a resilient infrastructure for hosting at scale, but infrastructure alone is not a guarantee for a site to perform well in all scenarios. To increase a site’s resiliency, SQL database queries should be optimized wherever possible.

Optimizing core queries becomes crucial as a site’s posts table grows larger. Learn how to identify slow queries and optimize the underlying code to improve site performance and resilience.

  • Identify slow queries

    Slow queries should be investigated and optimized wherever possible. Several resources are available for identifying slow database queries when they occur and identifying their source.

  • Optimize core queries at scale

    Performance issues can be caused by core WordPress queries that perform well when a site has a small amount of data, but as the volume of site content increases the queries require a longer amount of time to execute.

  • Defining post_status or post_type

    By default, the post_status of a query is set to publish for anonymous users on the front end.

  • Fix performance issues by filtering wp_unique_post_slug

    The wp_unique_post_slug function makes it possible to avoid slug conflicts by appending an integer to the end of the newer slug, but this can become problematic because the function iterates through the database to find the next ID.

  • Avoid post__not_in

    The WP_Query argument post__not_in appears to be a helpful option, but it can lead to poor performance on a busy and/or large site due to affecting the cache hit rate.

  • Retrieving remote data

    Remote calls such as wp_remote_get(), wp_safe_remote_get() and wp_oembed_get() should rely on the WordPress HTTP API (not cURL) and should be cached.

  • Best practices for database queries

    WordPress API functions should be used instead of direct database queries for fetching and manipulating data whenever possible.

  • Meta queries

    There are two types of indexes available for meta query usage on the VIP Platform, and many use cases can be modified to avoid performance problems.

  • Taxonomy queries should set `include_children` to false

    As of WordPress 4.4, terms have been split, adding ‘include_children’ => true to almost all taxonomy queries.

Last updated: December 29, 2025

Relevant to

  • WordPress