-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Price range widget checks variations too #937
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,22 +138,31 @@ function wpsc_price_range( $args = null ) { | |
|
||
} | ||
|
||
if(isset($_GET['range'])){ | ||
if ( isset( $_GET['range'] ) ) { | ||
add_filter( 'posts_where', 'wpsc_range_where' ); | ||
} | ||
|
||
function wpsc_range_where( $where ) { | ||
global $wpdb, $wp_query; | ||
$range = explode('-', $_GET['range']); | ||
if(!strpos($where,'wpsc-product')) | ||
return $where; | ||
if(!$range[0]){ | ||
$where .= " AND $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key=\"_wpsc_price\" AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") "; | ||
}elseif(!$range[1]){ | ||
$where .= " AND $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key=\"_wpsc_price\" AND $wpdb->postmeta.meta_value > " . ( $range[0]-1 ) . ") "; | ||
}elseif($range[1] && $range[0]){ | ||
$where .= " AND $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key=\"_wpsc_price\" AND $wpdb->postmeta.meta_value > " . ( $range[0]-1 ) . " AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") "; | ||
global $wpdb; | ||
|
||
if ( ! strpos( $where, 'wpsc-product' ) ) { | ||
return $where; | ||
} | ||
|
||
$range = explode( '-', $_GET['range'] ); | ||
|
||
if ( empty( $range ) || $range[0] == 'all' ) { | ||
return $where; | ||
} | ||
|
||
if ( ! $range[0] ) { | ||
$where .= " AND ( $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") OR $wpdb->posts.id IN ( SELECT $wpdb->posts.post_parent FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->posts.post_type = 'wpsc-product' AND $wpdb->posts.post_status = 'inherit' AND $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") ) "; | ||
} elseif ( ! $range[1] ) { | ||
$where .= " AND ( $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value > " . ( $range[0] - 1 ) . ") OR $wpdb->posts.id IN ( SELECT $wpdb->posts.post_parent FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->posts.post_type = 'wpsc-product' AND $wpdb->posts.post_status = 'inherit' AND $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value > " . ( $range[0] - 1 ) . ") ) "; | ||
} elseif( $range[1] && $range[0] ) { | ||
$where .= " AND ( $wpdb->posts.id IN ( SELECT $wpdb->posts.id FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value > " . ( $range[0] - 1 ) . " AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") OR $wpdb->posts.id IN ( SELECT $wpdb->posts.post_parent FROM $wpdb->posts JOIN $wpdb->postmeta on $wpdb->postmeta.post_id = $wpdb->posts.id WHERE $wpdb->posts.post_type = 'wpsc-product' AND $wpdb->posts.post_status = 'inherit' AND $wpdb->postmeta.meta_key='_wpsc_price' AND $wpdb->postmeta.meta_value > " . ( $range[0] - 1 ) . " AND $wpdb->postmeta.meta_value < " . ( $range[1] + 1 ) . ") ) "; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume these queries to be much more computationally expensive. It would be weird and likely just as expensive to use WP_Meta_Query, though we'd get the benefit of caching. Rather than do that, why don't we set a cache key for the range requested and cache the results of the query? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean to Transients API for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, transients would be fine. Be sure to invalidate the transient whenever updating a new price though. |
||
|
||
return $where; | ||
} | ||
?> | ||
?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to check
if ( false === strpos( $where, 'wpsc-product' ) )