Created
December 4, 2013 21:17
-
-
Save brycejacobson/7795733 to your computer and use it in GitHub Desktop.
Get custom field date in WP_Query and show the post if the date is in the future. Using Advance Custom Fields.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$today = date('Ymd', strtotime('-1 day')); | |
// WP_Query arguments | |
$args = array ( | |
'post_type' => 'construction_bids', | |
'posts_per_page' => -1, | |
'meta_query' => array( | |
array( | |
'key' => 'bid_deadline', | |
'value' => $today, | |
'compare' => '>', | |
), | |
), | |
); | |
// the query | |
$query = new WP_Query( $args ); ?> | |
<?php if ( $query->have_posts() ) : ?> | |
<!-- pagination here --> | |
<!-- the loop --> | |
<?php while ( $query->have_posts() ) : $query->the_post(); $date = DateTime::createFromFormat('Ymd', get_field('bid_deadline')); ?> | |
<h2><a href="<? echo get_permalink(); ?>"><?php echo get_the_title(); ?></a></h2> | |
<p><strong>Bid Deadline:</strong> 3:00 PM, <?php echo $date->format('F j Y'); ?></p> | |
<h3>Summary:</h3> | |
<?php echo the_field('summary'); ?> | |
<?php endwhile; ?> | |
<!-- end of the loop --> | |
<!-- pagination here --> | |
<?php wp_reset_postdata(); ?> | |
<?php else: ?> | |
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot, saved me some time :)