WP_Query changes in WordPress 6.8

<div style&equals;"text-align&colon;center"><&sol;div><div>&NewLine;<p>WordPress 6&period;8 includes some caching optimizations that may affect themes and plugins using the <code>WP&lowbar;Query&colon;&colon;get&lpar;&rpar;<&sol;code> method and the <code>WP&lowbar;Query&colon;&colon;&dollar;query&lowbar;vars<&sol;code> property&period;<&sol;p>&NewLine;<p>In <a href&equals;"https&colon;&sol;&sol;core&period;trac&period;wordpress&period;org&sol;ticket&sol;59516">&num;59516<&sol;a>&comma; <code>WP&lowbar;Query<&sol;code> was optimized to improve cache hits for queries with equivalent arguments&period;<&sol;p>&NewLine;<p>This enhancement improves performance for sites that run equivalent queries with a different order of arguments&period; The impact will be most noticeable on sites without a persistent cache&comma; as these equivalent queries would run multiple times on a single page request&comma; whereas they will now run once&period;<&sol;p>&NewLine;<p>As such theme and plugin authors making use of filters within <code>WP&lowbar;Query<&sol;code> &lpar;source code&colon; <a href&equals;"https&colon;&sol;&sol;github&period;com&sol;WordPress&sol;wordpress-develop&sol;blob&sol;6&period;8&sol;src&sol;wp-includes&sol;class-wp-query&period;php">GitHub<&sol;a>&comma; <a href&equals;"https&colon;&sol;&sol;core&period;trac&period;wordpress&period;org&sol;browser&sol;branches&sol;6&period;8&sol;src&sol;wp-includes&sol;class-wp-query&period;php">trac<&sol;a>&rpar; are recommended to check their code for compatibility with WordPress 6&period;8&period; An example of code that would be affected by this is using equality to check for the contents of an array&colon;<&sol;p>&NewLine;<pre class&equals;"wp-block-code"><code lang&equals;"php" class&equals;"language-php">&dollar;query &equals; new WP&lowbar;Query&lpar; array&lpar; 'post&lowbar;type' &equals;> array&lpar; 'post'&comma; 'page' &rpar; &rpar; &rpar;&semi;&NewLine;&NewLine;add&lowbar;filter&lpar; 'posts&lowbar;where'&comma; function &lpar; &dollar;where&comma; &dollar;query &rpar; &lbrace;&NewLine;        &sol;&sol; True in WordPress 6&period;7&comma; false in WordPress 6&period;8&NewLine;        &sol;&sol; WordPress 6&period;7 returns array&lpar; 'post'&comma; 'page' &rpar;&NewLine;        &sol;&sol; WordPress 6&period;8 returns array&lpar; 'page'&comma; 'post' &rpar;&NewLine;        if &lpar; array&lpar; 'post'&comma; 'page' &rpar; &equals;&equals;&equals; &dollar;query->get&lpar; 'post&lowbar;type' &rpar; &rpar; &lbrace;&NewLine;                &sol;&sol; Modify WHERE clause&period;&NewLine;        &rcub;&NewLine;&NewLine;        return &dollar;where&semi;&NewLine;&rcub;&comma; 10&comma; 2 &rpar;&semi;<&sol;code><&sol;pre>&NewLine;<p>When comparing the contents of two arrays for <em>equivalence<&sol;em>&comma; it is recommended to use the code <code>empty&lpar; array&lowbar;diff&lpar; &sol;&ast; arrays &ast;&sol; &rpar; &rpar;<&sol;code> rather than equality comparisons&period; See this <a href&equals;"https&colon;&sol;&sol;3v4l&period;org&sol;fAlcb">example for a demonstration<&sol;a>&period;<&sol;p>&NewLine;<h2 class&equals;"wp-block-heading"><strong>Standardized arguments&period;<&sol;strong><&sol;h2>&NewLine;<p>The most common example of where these changes will improve performance is when querying multiple post types&colon;<&sol;p>&NewLine;<pre class&equals;"wp-block-code"><code lang&equals;"php" class&equals;"language-php">&dollar;q1 &equals; new WP&lowbar;Query&lpar; &lbrack; 'post&lowbar;type' &equals;> &lbrack; 'post'&comma; 'page' &rsqb; &rsqb; &rpar;&semi;&NewLine;&dollar;q2 &equals; new WP&lowbar;Query&lpar; &lbrack; 'post&lowbar;type' &equals;> &lbrack; 'page'&comma; 'post'&rsqb; &rsqb; &rpar;&semi;&NewLine;&dollar;q3 &equals; new WP&lowbar;Query&lpar; &lbrack; 'post&lowbar;type' &equals;> &lbrack; 'page'&comma; 'post'&comma; 'post' &rsqb; &rsqb; &rpar;&semi;<&sol;code><&sol;pre>&NewLine;<p>In WordPress 6&period;7 and earlier&comma; these queries would each result in database queries as they were not seen as equivalent in the resulting database query and cache key&period;<&sol;p>&NewLine;<p>To standardize equivalent queries&comma; <code>WP&lowbar;Query<&sol;code> now sorts and type casts arguments as appropriate&period; For each of the queries above the post types are sorted alphabetically and any duplicates removed&period; In WordPress 6&period;8 the <code>&colon;&colon;get&lpar;&rpar;<&sol;code> method and <code>&colon;&colon;&dollar;query&lowbar;vars<&sol;code> property will differ from the arguments passed to <code>&dollar;q1<&sol;code> and <code>&dollar;q3<&sol;code>&colon;<&sol;p>&NewLine;<pre class&equals;"wp-block-code"><code lang&equals;"php" class&equals;"language-php">&dollar;q1->get&lpar; 'post&lowbar;type' &rpar; &sol;&sol; returns &lbrack; 'page'&comma; 'post' &rsqb;&NewLine;&dollar;q2->get&lpar; 'post&lowbar;type' &rpar; &sol;&sol; returns &lbrack; 'page'&comma; 'post' &rsqb;&NewLine;&dollar;q3->get&lpar; 'post&lowbar;type' &rpar; &sol;&sol; returns &lbrack; 'page'&comma; 'post' &rsqb;&NewLine;&NewLine;&dollar;q1->query&lowbar;vars&lbrack;'post&lowbar;type'&rsqb; &equals;&equals;&equals; &lbrack; 'page'&comma; 'post' &rsqb;&NewLine;&dollar;q2->query&lowbar;vars&lbrack;'post&lowbar;type'&rsqb; &equals;&equals;&equals; &lbrack; 'page'&comma; 'post' &rsqb;&NewLine;&dollar;q3->query&lowbar;vars&lbrack;'post&lowbar;type'&rsqb; &equals;&equals;&equals; &lbrack; 'page'&comma; 'post' &rsqb;<&sol;code><&sol;pre>&NewLine;<p>For items that accept values as either an integer or a string&comma; these have been sorted and typecast as appropriate&comma; for example <code>author&lowbar;&lowbar;not&lowbar;in &equals;> &lbrack; '2'&comma; '1' &rsqb;<&sol;code> becomes <code>author&lowbar;&lowbar;not&lowbar;in &equals;> &lbrack; 1&comma; 2 &rsqb;<&sol;code>&period; A full list of affected arguments can be found in the commit message <a href&equals;"https&colon;&sol;&sol;core&period;trac&period;wordpress&period;org&sol;changeset&sol;59766">&lbrack;59766&rsqb;<&sol;a>&period;<&sol;p>&NewLine;<p>Due to differences in the code paths when the post type and status are passed as a string&comma; these are not type cast to an array <&sol;p>&NewLine;<pre class&equals;"wp-block-code"><code lang&equals;"php" class&equals;"language-php">&dollar;q4 &equals; new WP&lowbar;Query&lpar; &lbrack; 'post&lowbar;type' &equals;> 'post' &rsqb; &rpar;&semi;&NewLine;&dollar;q4->get&lpar; 'post&lowbar;type' &rpar; &sol;&sol; returns 'post'<&sol;code><&sol;pre>&NewLine;<p>These changes are part of an ongoing effort to <a href&equals;"https&colon;&sol;&sol;make&period;wordpress&period;org&sol;performance&sol;">improve the performance of WordPress<&sol;a>&period; The core team are monitoring the changes for any major issues that may occur&comma; see <a href&equals;"https&colon;&sol;&sol;core&period;trac&period;wordpress&period;org&sol;ticket&sol;63255">&num;63255<&sol;a>&period; <&sol;p>&NewLine;<p class&equals;"has-text-align-right">Props <a href&equals;"https&colon;&sol;&sol;profiles&period;wordpress&period;org&sol;joemcgill&sol;" class&equals;"mention"><span class&equals;"mentions-prefix">&commat;<&sol;span>joemcgill<&sol;a> and <a href&equals;"https&colon;&sol;&sol;profiles&period;wordpress&period;org&sol;jorbin&sol;" class&equals;"mention"><span class&equals;"mentions-prefix">&commat;<&sol;span>jorbin<&sol;a> for their review of this post&period;<&sol;p>&NewLine;<p class&equals;"o2-appended-tags"><a href&equals;"https&colon;&sol;&sol;make&period;wordpress&period;org&sol;core&sol;tag&sol;6-8&sol;" class&equals;"tag"><span class&equals;"tag-prefix">&num;<&sol;span>6-8<&sol;a>&comma; <a href&equals;"https&colon;&sol;&sol;make&period;wordpress&period;org&sol;core&sol;tag&sol;dev-notes&sol;" class&equals;"tag"><span class&equals;"tag-prefix">&num;<&sol;span>dev-notes<&sol;a>&comma; <a href&equals;"https&colon;&sol;&sol;make&period;wordpress&period;org&sol;core&sol;tag&sol;dev-notes-6-8&sol;" class&equals;"tag"><span class&equals;"tag-prefix">&num;<&sol;span>dev-notes-6-8<&sol;a>&comma; <a href&equals;"https&colon;&sol;&sol;make&period;wordpress&period;org&sol;core&sol;tag&sol;performance&sol;" class&equals;"tag"><span class&equals;"tag-prefix">&num;<&sol;span>performance<&sol;a><&sol;p>&NewLine;<&sol;div>&NewLine;

Sponsored
Sponsored
A WordPress Commenter

Recent Posts

Cloudways Brings Back Prepathon Next Week With Focus on Gen Z and Gen Alpha

Cloudways is bringing back its free Prepathon online event next week, from September 30 to…

2 days ago

Fueled Layoffs Spark Tension After Former Employee Pre-Empts Announcement

Fueled has confirmed layoffs this week, cutting 4–5% of its workforce. But the news reached…

3 days ago

Nick Hamze’s ‘Cool Kids’ Post Kicks Off Fresh Debate on WordPress’s Image Problem

After calling for “more weirdness” in WordPress theme design earlier this year, Nick Hamze has…

4 days ago

New FAIR 1.0 Release Brings Decentralized Package Management to WordPress

FAIR has reached its first major milestone with the release of version 1.0 this week,…

4 days ago

Performance Chat Summary: 23 September 2025

The full chat log is available beginning here on Slack. WordPress Performance Trac tickets @westonruter…

5 days ago

From RV Life to CEO: Jon Penland’s Unlikely Road to Leading Kinsta

Back in 2011, Jon Penland was selling centrifugal pumping units into the water and wastewater…

6 days ago