I have a similar issue. I have this:
$args = array(
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'cat' => '2'
);
and I want to add the additional sorting where the “event_date” custom field is either on or later than the current date. Any help would be appreciated.
Ok, tried this:
<?php
$today = date('MM d, yy');
$args = array (
'post_type' => 'post',
'meta_query' => array(
array(
'meta_key' => 'event_date',
'compare' => '>=',
'value' => $today,
),
array(
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'cat' => '2'
)
),
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post(); ?>
But it does not return the correct result. It shows all the events.
Excellent. It works! So what if I want to only display events with an event_date that is on or after the current date?
Will this work with get_posts as well? I have a similar issue what I want to display all the posts with the category “event” and I want to order them based on Advanced custom field called event_date. Here is how I want to display each post:
<div class="home-post-area">
<div class="home-post-image">
<?php the_post_thumbnail('', array('class' => 'img-responsive')); ?>
<div class="home-post-image-overlay">
<h3><?php the_field('event_date'); ?> <?php the_field('event_price'); ?></h3>
<h4><?php the_title();?></h4>
</div>
</div>
<div class="home-post-content">
<?php the_excerpt();?>
<p><a href="<?php the_permalink() ?>"><atrong>>> MORE</atrong></a></p>
</div>
</div>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.