[Plugin: Ajax Post Filter] – A Taxonomy mysql query takes ages
-
I am listing products in my wordpress page and have a taxonomy filter that filters posts/ results by AJAX using http://wordpress.org/extend/plugins/ajax-post-filter/ plugin. So for example, I have 2 TVs as products and there are 8 taxonomies, 6 of which are common between these two TVS. The problem is, when I select around 5 different taxonomies, the SQL query takes nearly a minute to return a result. I’ve included a SQL statement when you filter by 1 taxonomy, and another when you select 5 taxonomies. I’d be very grateful for any advice on how to amend the query and speed things up a bit. Thanks
**ONE ACTIVE FILTER**
Array
(
[post_type] => Array
(
[0] => product
)[posts_per_page] => 15
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => feature
[field] => id
[terms] => 25
))
[orderby] => title
[order] => ASC
[post_status] => publish
[paged] => 1
)`SELECT SQL_CALC_FOUND_ROWS wp_posts.*
FROM wp_posts
INNER JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id)
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN (25) )
AND wp_posts.post_type IN (‘product’)
AND (wp_posts.post_status = ‘publish’)
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_title ASC
LIMIT 0, 15`**FIVE ACTIVE FILTERS**
Array
(
[post_type] => Array
(
[0] => product
)[posts_per_page] => 15
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => feature
[field] => id
[terms] => 25
)[1] => Array
(
[taxonomy] => feature
[field] => id
[terms] => 26
)[2] => Array
(
[taxonomy] => feature
[field] => id
[terms] => 16
)[3] => Array
(
[taxonomy] => feature
[field] => id
[terms] => 17
)[4] => Array
(
[taxonomy] => feature
[field] => id
[terms] => 18
)[relation] => OR
)[orderby] => title
[order] => ASC
[post_status] => publish
[paged] => 1
)`SELECT SQL_CALC_FOUND_ROWS wp_posts . *
FROM wp_posts
INNER JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id)
INNER JOIN wp_term_relationships AS tt1
ON (wp_posts.ID = tt1.object_id)
INNER JOIN wp_term_relationships AS tt2
ON (wp_posts.ID = tt2.object_id)
INNER JOIN wp_term_relationships AS tt3
ON (wp_posts.ID = tt3.object_id)
INNER JOIN wp_term_relationships AS tt4
ON (wp_posts.ID = tt4.object_id)
WHERE 1 = 1
AND (
wp_term_relationships.term_taxonomy_id IN (25)
OR tt1.term_taxonomy_id IN (26)
OR tt2.term_taxonomy_id IN (16)
OR tt3.term_taxonomy_id IN (17)
OR tt4.term_taxonomy_id IN (18)
)
AND wp_posts.post_type IN (‘product’)
AND (wp_posts.post_status = ‘publish’)
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_title ASC
LIMIT 0 , 15`
- The topic ‘[Plugin: Ajax Post Filter] – A Taxonomy mysql query takes ages’ is closed to new replies.