/**
* Получает экстремальнве значения ценв в категории товара
* @param $term_id - id категории товара
*
* @return mixed
*/
function wpp_get_extremes_price_in_product_cat( $term_id ) {
global $wpdb;
$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'
";
$result = $wpdb->get_results( $wpdb->prepare( $sql, $term_id ) );
return $result[ 0 ];
}
$sql = "
SELECT MIN( CAST(meta_value AS SIGNED) ) AS min_price, MAX( CAST(meta_value AS SIGNED) ) 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'
";