Home / CMS & DEV / Optimize SQL queries

CMS & DEV

Optimize SQL queries for your WordPress themes

By the team UseStackPulse Updated on August 26, 2026 8 min reading

A poorly optimized theme can multiply SQL queries by ten. WP_QUERY well configured and the transients drastically reduce the database load.

Advertising / AD Leaderboard 728×90

Avoid redundant requests with WP_QUERY

$query = new WP_Query([
    'post_type' => 'post',
    'posts_per_page' => 10,
    'no_found_rows' => true,
    'update_post_meta_cache' => false,
    'update_post_term_cache' => false,
]);

Caching with the Transients

function get_featured_products() {
    $cached = get_transient('featured_products');
    if ($cached !== false) return $cached;

    $products = new WP_Query(['post_type' => 'product', 'meta_key' => 'featured']);
    set_transient('featured_products', $products->posts, HOUR_IN_SECONDS);

    return $products->posts;
}

Tip: Enable Query Monitor in the development environment to visualize exactly what queries are slowing down your theme.

Advertising / AD In-article 336×280

frequently asked questions

no_found_rows breaks pagination?

Yes, use it only on queries without pagination; Otherwise keep Found_Rows active.

Do transients survive a Redis cache object?

Yes, with a persistent cache object plugin, transients are automatically stored in memory rather than in base.

Scroll to top