Created
February 18, 2019 20:44
-
-
Save eto4detak/985bfa2e0cf871462ca9fd833d0add5b to your computer and use it in GitHub Desktop.
woo php min max price category
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
<?php | |
// мвкс и мин | |
function wpp_get_extremes_price_in_product_cat( $term_id ) { | |
global $wpdb; | |
$results = $wpdb->get_col( " | |
SELECT pm.meta_value | |
FROM {$wpdb->prefix}term_relationships as tr | |
INNER JOIN {$wpdb->prefix}term_taxonomy as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id | |
INNER JOIN {$wpdb->prefix}terms as t ON tr.term_taxonomy_id = t.term_id | |
INNER JOIN {$wpdb->prefix}postmeta as pm ON tr.object_id = pm.post_id | |
WHERE tt.taxonomy LIKE 'product_cat' | |
AND t.term_id = {$term_id} | |
AND pm.meta_key = '_price' | |
"); | |
return $results; | |
// $sql = " | |
// SELECT MIN( meta_value ) as min_price , MAX( meta_value ) as max_price | |
// FROM {$wpdb->posts} | |
// INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) | |
// INNER JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id) | |
// WHERE | |
// ( {$wpdb->term_relationships}.term_taxonomy_id IN (%d) ) | |
// AND {$wpdb->posts}.post_type = 'product' | |
// AND {$wpdb->posts}.post_status = 'publish' | |
// AND {$wpdb->postmeta}.meta_key = '_price' | |
// "; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment