Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Modify the Query Directly */
- $today = date( 'Y-m-d' );
- $args = array(
- 'post_type' => 'bgmp',
- 'meta_query' => array(
- array(
- 'key' => 'coupon_end_date',
- 'value' => $today,
- 'compare' => '>=',
- 'type' => 'DATETIME'
- )
- )
- );
- $the_query = new WP_Query( $args );
- /* OR use pre_get_posts */
- add_action( 'pre_get_posts', 'fm_modify_coupon_query' );
- function fm_modify_coupon_query( $query ) {
- // Check to make sure we're on the front end, is main query, and within the coupon taxonomy
- if( ! is_admin() && $query->is_main_query() && is_tax('coupon') ) {
- $today = date( 'Y-m-d' );
- $query->set('meta_key', 'coupon_end_date');
- $query->set('meta_value', $today);
- $query->set('compare', '>=');
- $query->set('type', 'DATETIME');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement