Skip to content

Instantly share code, notes, and snippets.

@vagelisp
Last active May 5, 2019 11:04
Show Gist options
  • Save vagelisp/0188e9fc83777f018bd9f06316f2250b to your computer and use it in GitHub Desktop.
Save vagelisp/0188e9fc83777f018bd9f06316f2250b to your computer and use it in GitHub Desktop.
function post_change_expired_function_new () {
if (is_admin()):
return;
endif;
if (is_single()):
$offer_coupon_date = get_post_meta( $post->ID, 'rehub_offer_coupon_date', true );
$timestamp1 = strtotime($offer_coupon_date) + 86399;
$seconds = $timestamp1 - (int)current_time('timestamp',0);
$days = floor($seconds / 86400);
$seconds %= 86400;
if ($days > 0):
$coupon_style = '';
update_post_meta( get_the_ID(), 're_post_expired', 'no' );
elseif ($days == 0):
$coupon_style = '';
update_post_meta( get_the_ID(), 're_post_expired', 'no' );
else:
$coupon_text = __('Expired', 'rehub_framework');
$coupon_style = ' expired_coupon';
update_post_meta( get_the_ID(), 're_post_expired', 1 );
endif;
endif;
}
add_action ( 'wp', 'post_change_expired_function_new', 100 );
function exclude_expired($query) {
if (is_admin()):
return;
endif;
if (is_archive()):
return;
endif;
if (is_single()):
return;
endif;
$exclude = array();
if ( $query->is_main_query() ) {
$expired = get_posts(array(
'post_type' => 'post',
'meta_query' => array(
array(
'key' => 're_post_expired',
'value' => '1',
'compare' => '==',
),
),
));
foreach($expired as $hide) {
$exclude[] = $hide->ID;
}
$query->set('post__not_in', $exclude);
}
}
add_filter( 'pre_get_posts', 'exclude_expired', 900 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment