0

I have created filtering system where is executed WordPress Query with lots of meta_query data. In total there are 24 possible filters with various type and compare values.

At the moment there is ~2800 rows within filtering is executed.

Of course, filtering is very slow, sometimes it takes 30-60 seconds to execute filtering and display some results. After 5-6 such filtering action there is Warning: mysqli_query(): MySQL server has gone away warning.

I am aware of SQL INDEX method, but how can we apply it to WordPress database? Is there any other way to improve filtering speed time in WordPress? What are your suggestions?

Thank you for help.

Paulius Vitkus
  • 129
  • 1
  • 4
  • 15
  • 1
    You can add indexes to your WordPress database tables at any time, either write it in as an SQL query or do it straight from phpMyAdmin. Though, it seems like your issue is poor data structure. It almost sounds like you should consider using taxonomies and terms instead of postmeta - either that or consider setting up a separate custom relational table. Postmeta isn't *intended* to be a filter catalyst because it's inherently slow. You could also try using a manually optimized SQL Query with `$wpdb->query()` instead of a `WP_Query` to see if you can write a better query by hand. – Xhynk Oct 06 '20 at 21:27
  • Show us the query. This may help: http://mysql.rjweb.org/doc.php/index_cookbook_mysql#speeding_up_wp_postmeta – Rick James Oct 15 '20 at 06:17

0 Answers0