I’m currently building a website where I need to show coming events. I’m building the website on the Salient WordPress theme, and trying to customize it a bit with some code in a child theme.
I’m changing the build in blog post loop of the theme, to show events instead. Within the code I made some few changes to sort them in the correct order (nog publish date, but event date) but I can’t seem to figure out how to exclude events that have their date passed.
if( $orderby !== ‘view_count’ ) {
$today = date(‘l j F’);
$nectar_blog_arr = array(
‘post_type’ => ‘evenement’,
‘posts_per_page’ => $posts_per_page,
‘post_status’ => ‘publish’,
‘meta-key’ => ‘event_startdate’,
‘meta_query’ => array(
‘relation’ => ‘AND’,
‘date_clause’ => array(
‘key’ => ‘event_startdate’,
‘value’ => $today,
‘type’ => ‘DATE’,
‘compare’ => ‘>=’
),
),
‘orderby’ => array(
‘date_clause’ => ‘ASC’,
),
‘offset’ => $post_offset,
‘category_name’ => $category,
‘paged’ => $paged
);
Any tips or tricks?
Note: I tried many pieces of code that I found on this form, or other website, but some codes just breaks the loop, and won’t show the loop at all. Without any PHP errors as well. Weird right?
Thanks in advance for all the help and suggestions!
It seems unlikely that ACF is storing the date in meta with format l j F
(ex: Thursday 14 November
) or L j F
(ex: 1 14 November
). Double-check the format of the date value in the post meta, and correct the first parameter in your date()
calls to match.
If it truly is being stored in that format, you will not be able to filter by the post meta value.
Additionally, the meta-key
parameter should be meta_key
.