Created
December 6, 2017 16:12
-
-
Save luancmaia/2c1dbb39531ef4af9bbdd4c7d087c44a to your computer and use it in GitHub Desktop.
PHP Filtro
This file contains hidden or 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
add_action( 'pre_get_posts', 'query_filter_category' ); | |
function query_filter_category( $query ) { | |
if ( $_GET && isset( $_GET['tid'] ) && $query->is_main_query() ) { | |
$tid = $_GET['tid']; | |
$tids = []; | |
$tax_query = ['relation' => 'OR']; | |
global $wpdb; | |
foreach($tid as $t): | |
$result = $wpdb->get_results( 'SELECT object_id FROM ' . $wpdb->prefix . 'term_relationships WHERE term_taxonomy_id = ' . $t ); | |
if ( $result ) { | |
foreach($result as $r): | |
$tids[] = $r->object_id; | |
endforeach; | |
} | |
//$tax_query[] = [ 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $t ]; | |
endforeach; | |
$query->set('post__in', $tids); | |
} | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment