Comparing values in pre_get_posts
-
I have a function that I would like to run on the back-end so that it doesn’t load a post that will be hidden. I’m confused as to get it working in
pre_get_post
.The code:
<?php if ((get_field('status_type') == 'alert') && get_field('status_start_date') < date( 'U', current_time( 'timestamp', 0 ) ) && (get_field('status_end_date')=='')):?>
I’ve looked online and couldn’t find anything close to a solution. This is what I’ve done so far:
function alerts_opby( $qvars ){ $qvars[] = 'opby_alerts'; return $qvars; } add_filter( 'query_vars', 'alerts_opby' ); function opby_query( $query ) { if (isset( $query->$qvars['opby_alerts'] )) { $query->set('tax_query', array(array('taxonomy' => 'post_format','field' => 'slug','terms' => array( 'post-format-status' ),'operator'=> 'IN'), 'orderby' =>'meta_value','meta_key', 'breaking_news'), 'meta_query', array( array( 'value' => date("U"), 'compare' => '<', 'type' => 'NUMERIC' ), array( 'value' => array(get_field('status_time_duration', $post-id) + get_the_time('U') > date( 'U', current_time( 'timestamp', 0 ) )), 'compare' => '<', 'type' => 'NUMERIC' )), $query->set('posts_per_page', -1)); } return $query; } add_action( 'pre_get_posts', 'opby_query' );
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Comparing values in pre_get_posts’ is closed to new replies.