Database query- How the theme works

Home » Knowledge Base » Database query- How the theme works
Knowledge Base No Comments

When doing searches or any other database related requests we are always using the wordpress api. – more exaxctly the wp api instruction called wp_query https://codex.wordpress.org/Class_Reference/WP_Que…

We are NOT using our custom SELECT’s or any other manual query to the sql database. This is the best practice when writing WordPress themes and themeforest will not even accept the theme for sale if it will have such direct queries.

We also did not add new custom tables but use only the ones in a wordpress default install.

Now, since we are using the wordpress api and we are using the default tables it means that all the queries are are made by WordPress core.

We have had many clients that said  that the the loading times are very very slow because the database is not optimized and goes to retrieve slow query. This is equivalent with saying wordpress db design is a poor one. Which  we think is not the case.

Any other wordpress theme will use the same mechanism so is not something particular to us.

Since we did not create custom tables we did not add indexes on any tables . The reason your indexes are not used is probably because the wp queries are not needing those.  Please look over this document

https://codex.wordpress.org/Database_Description and see the database structure and also see the index chapters.

So far(we have 5+ years in working with wp ) the only problems we discover are related to the meta_query part of a wp_query . In your case meta_query are the Features And Amenit ies from the search form . This is a real problem on wordpress an you can see more details here http://wordpress.stackexchange.com/questions/15889…

However the latest updates comes with a partial rewrite of the search algo while the version will release next week will have the full implementation of the solution.

When you have search speed issues, the step in this investigation is to look how the mysql is configured and if any search you are doing is increasing the load on it.

Also you can work on a fine tuning with indexes – although i don;t think you will be able to improve it.

Go to advanced_Ssearch_results.php and do a print_r($prop_selection);

This will print the results object of the wp_query and it will show you the actual mysql query wordrpress does.