Quantcast
Channel: User andrewsi - Stack Overflow
Viewing all articles
Browse latest Browse all 51

Answer by andrewsi for Wordpress wp_query taking a long time

$
0
0

One thing you can do is tweak the tax_query parameter; you're joining the same table six times, and each one has an IN statement - that's producing some very inefficient SQL, as you've noticed.

The manual page for WP_Query has a few examples for tax_query, and it looks like you can combine all those different IDs into a single entity, which will reduce the SQL complexity considerably.

array(
    'post_status' => 'publish',
    'post_type' => 'post',
    'offset' => 0,
    'posts_per_page' => 21,
    'tax_query' =>
        array(
            0 => array(
                    'taxonomy' => 'category',
                    'field' => 'id',
                    'terms' => array (5, 17, 20, 33, 55, 83), 
            )            )
    )

That should fetch terms with any of those IDs, and should do it more efficiently.


Viewing all articles
Browse latest Browse all 51

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>