Created
June 24, 2021 23:33
-
-
Save mishterk/6bea2b6226fafac84fa44190ec14ac5d to your computer and use it in GitHub Desktop.
Some handy considerations when running WP_Query to speed up the query depending on the requirements. This demonstrates using specific post ID's from ACF custom database tables in conjunction with some built in WP_Query args to save on internal queries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = new WP_Query([ | |
// Standard query args. Using post__in can be much faster. If searching ACF custom | |
// database tables data, plugin the found post IDs in here. | |
'post_type' => 'post', | |
'post__in' => [1,2,3], // array of post IDs | |
// Optional args to improve performance. Use these to cut down on internal | |
// complexity and make the overall internal SQL faster. | |
// Don't need total found rows? | |
// Set this to true to save on additional queries. | |
'no_found_rows' => true, | |
// Don't need WordPress to run the meta query for all meta data for found posts? | |
// Set this to false to save on additional queries. | |
'update_post_meta_cache' => false, | |
// Don't need to worry about taxonomies for found posts? | |
// Set this to false to save on additional queries. | |
'update_post_term_cache' => false, | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment