Home › Forums › General Issues › Show only upcoming events from current month › Reply To: Show only upcoming events from current month
The first problem you have is that you can’t use “Date” as the meta type because ACF date fields are not stored as “dates” in the database. the type needs to be strings or numbers.
date('Ymt')
will return the last day of the month for a given date.
<?php
$today = date('Ymd');
$last_of_month = date('Ymt', strtotime(date('Y-m-d')));
$args = array(
'posts_per_page' => 7,
'post_type' => 'competicions',
'orderby' => 'meta_value',
'order' => 'asc',
'meta_key' => 'datahora_prova', //ACF date field
'meta_query' => array(
array(
'key' => 'datahora_prova',
'value' => $today,
'compare' => '>=',
),
array(
'key' => 'datahora_prova',
'value' => $last_of_month,
'compare' => '<=',
)
)
);
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!
🚀 ACF & ACF PRO 6.0.7 are now available.
— Advanced Custom Fields (@wp_acf) January 18, 2023
✨This release contains bug fixes and improvements while we continue to work on the next major release of ACF.https://t.co/wQgAOpwmUI
© 2023 Advanced Custom Fields.
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.