Last active
March 13, 2022 03:41
-
-
Save RadGH/9ee5d3472f19644bf72ee8817c8b2516 to your computer and use it in GitHub Desktop.
WordPress get_terms replace INNER JOIN with STRAIGHT_JOIN using filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Step 1. Add the filters surrounding the get_terms (which should be used in your code) | |
add_filter( 'terms_clauses', 'rs_replace_inner_with_straight_joins', 20 ); | |
$terms = get_terms( $args ); | |
remove_filter( 'terms_clauses', 'rs_replace_inner_with_straight_joins', 20 ); | |
// Step 2. Add to functions.php or similar: | |
function rs_replace_inner_with_straight_joins( $pieces, $taxonomies = null, $args = null ) { | |
global $wpdb; | |
$s = 'INNER JOIN ' . $wpdb->prefix; | |
$r = 'STRAIGHT_JOIN ' . $wpdb->prefix; | |
$pieces['join'] = str_replace( $s, $r, $pieces['join'] ); | |
return $pieces; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for this, btw the function name doesn't match the one used in the add/remove filter