Optimize WP_Query

Optimize WP_Query

Every time you run query_posts() or create a new WP_Query() (secondary loop), four queries are run:

  1. Getting the posts according to your query string
  2. Calculating how many posts exist for this query (to create pagination)
  3. Loading all metadata for the posts
  4. Loading all taxonomy term information for the posts
  5. It is possible to turn off queries 2-4 to increase performance, like this:

XX

$my_query = new WP_Query(array(
    'no_found_rows' => true,
    'update_post_meta_cache' => false,
    'update_post_term_cache' => false
));

Andrew Nacin: WP_Query / WordPress In-depth - summary and highlights - Useful Snippets


Dodavanje indexa na tabele kako bi se ubrzao rad sa tabelama u bazi

Nije mi samo jasno zašto u originalu, u core WP, ovo nije dodato? Ne razumem koje su loše posledice?

Originalni članak koji do detalja objašnjava šta ovaj prvi plugin menja i zašto: Adding high-performance keys to MySQL tables to speed up WordPress and Speeding up WordPress database operations

More articles:


WordPress database index fixer by ManagedWPHosting.nl – Add indexes, keys, primary keys again to your WordPress database tables



Optimize Wordpress DB

WordPress wp_options table autoload micro-optimization - Sysadmins of the North

Add index to

ALTER TABLE wp_options ADD INDEX (`autoload`);

Add MySQL Indexes for WordPress Sites #24044 (Add index to wp_options to aid/improve performance) – WordPress Trac performance - Slow Query for the wp_options table - WordPress Development Stack Exchange

Convert MySQL MyISAM tables to InnoDB


Use WP_ALLOW_REPAIR to Repair the WordPress Database

Fix A Corrupted WordPress Database To fix the database connection error, you should log into your FTP client and go to the root WordPress folder. Then, edit the wp-config file there, by adding the following code and saving your file.

define("WP_ALLOW_REPAIR", true);

Once done, go to /wp-admin/maint/repair.php

How To Repair the WordPress Database via WP-CLI

If you’re using the command line to access your WordPress installation, you can use WP-CLI to repair the database.

To do this, use the wp db repair command. This can be the quickest way to repair the database.


date 26. Jun 2016 | modified 25. Jan 2023
filename: Wordpress » Performance » Optimize SQL Database and WP_Query