I am not sure whether this is an Advanced Custom Fields-related question, or a general PHP question, so I have also posted this to the ACF support forum, for those of you who are also looking for similar help.
I’m currently working on a local directory website, focussed specifically at it nightlife.
I have a Nightclub custom post type, with a number of ACF-powered fields, including events on each night. So far, the events are structured as Monday – Poster Image, Title. Tuesday – Poster Image, Title and so on.
What I’d like to do is only display events that are on tonight on the front page, but am having trouble narrowing the query down to ones with entries that are today. Here’s the query I’ve done so far:
<div id="home-featuredevent">
<h2>On Tonight</h2>
<?php $date = date('l' ); ?>
<?php $args = array( 'post_type' => 'nightclub' , 'posts_per_page' => 10, 'key' => 'event_$date' , 'value' => '' , 'compare' => '!=' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<a href="<?php the_field('event_$date' ); ?>"><?php the_field('event_$date_desc' ); ?></a>
At the moment, only the venue titles and links are showing.
Now, I’m fairly sure I’ve got my variable calls wrong, and I’m concerned that the structure of the ‘the_field(‘xyz’) is going to make it a bit more complicated.
I’m still starting out with PHP, so there is an excellent good chance I’ve just written bad code!
Any help would be great,
Tristan
I’m not sure why you are comparing anything when you would normally just query a
meta_key
for a certain day, maybe I mis-understood the question.The structure would be something like:
Then you just query posts for a particular day which has a meta field value that matches.
For example using
pre_get_posts
to alter your main query to only get posts where the value is equal to the actual day.or in your example it would be:
In my example I have hardcoded
'key' => 'day'
but you can use a variable instead.