Skip to content

Instantly share code, notes, and snippets.

@martinellimarco
Created December 16, 2023 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinellimarco/3bdef4a3bb3aeaec2ee78eec174ea88c to your computer and use it in GitHub Desktop.
Save martinellimarco/3bdef4a3bb3aeaec2ee78eec174ea88c to your computer and use it in GitHub Desktop.
FIX: WP All Export - slow export when using OR filters on postmeta (custom fields)

If you are experiencing high CPU usage using WP All Export with OR filters on post meta (custom fields) you may find it useful to apply this patch. We went down from exporting ~8000 records in 2 hours to exporting them in 5 minutes.

in src/Pro/Filtering/FilteringCPT.php change line 214 and 215

before:

                        $joinString = " INNER JOIN {$this->wpdb->postmeta} AS $table_alias ON ({$this->wpdb->posts}.ID = $table_alias.post_id) ";
                        $whereString = "$table_alias.meta_key = '$meta_key' AND $table_alias.meta_value " . $this->parse_condition($rule, false, $table_alias);

after:

                        $joinString = " INNER JOIN {$this->wpdb->postmeta} AS $table_alias ON ({$this->wpdb->posts}.ID = $table_alias.post_id AND $table_alias.meta_key = '$meta_key') ";
                        $whereString = "$table_alias.meta_value " . $this->parse_condition($rule, false, $table_alias);
--- src/Pro/Filtering/FilteringCPT.php 2023-12-16 13:44:38.817294704 +0000
+++ src/Pro/Filtering/FilteringCPT.php 2023-12-16 13:44:19.792826943 +0000
@@ -211,8 +211,8 @@
self::$variationWhere = $this->queryWhere;
}
- $joinString = " INNER JOIN {$this->wpdb->postmeta} AS $table_alias ON ({$this->wpdb->posts}.ID = $table_alias.post_id) ";
- $whereString = "$table_alias.meta_key = '$meta_key' AND $table_alias.meta_value " . $this->parse_condition($rule, false, $table_alias);
+ $joinString = " INNER JOIN {$this->wpdb->postmeta} AS $table_alias ON ({$this->wpdb->posts}.ID = $table_alias.post_id AND $table_alias.meta_key = '$meta_key') ";
+ $whereString = "$table_alias.meta_value " . $this->parse_condition($rule, false, $table_alias);
$this->queryJoin[] = $joinString;
$this->queryWhere .= $whereString;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment