Home › Forums › General Issues › Don't show post when they have passed
Hello !
I have a list of events and I would like to know if it’s possible to hide them when they have passed and how.
I call my date like that :
<?php
$date = get_field('jour_de_levenement', false, false);
$date = new DateTime($date);
?>
<p class="date-event"><?php echo $date->format('j'); ?>
<p class="month"><?php echo $date->format('F '); ?><?php echo $date->format('Y'); ?>
It seems like I need to use query_post and I tried this code :
<?php
$current_date = date('j F Y');
$current_date = strtotime( $current_date );
query_posts(array('post_type' => 'evenement',
'showposts' => 12,
'meta_key'=>'jour_de_levenement',
'orderby' => 'meta_value',
'order' => ASC));
while (have_posts()) : the_post();
$post_date = get('jour_de_levenement');
$post_date = strtotime( $post_date );
if( $post_date > $current_date ):
?>
<div class="date-custom-page">
<?php
$date = get_field('jour_de_levenement', false, false);
$date = new DateTime($date);
?>
<p class="date-event"><?php echo $date->format('j'); ?>
<p class="month"><?php echo $date->format('F '); ?><?php echo $date->format('Y'); ?>
<?php
endif;
endwhile;
?>
But it didn’t hide my old posts. I really appreciate if someone has an idea.
Thanks a lot.
Hi,
what field type is the jour_de_levenement field? And what value is returned?
Hi fabianmarz,
jour_de_levenement is a Date field and the code :
<p class="date-event"><?php echo $date->format('j'); ?>
<p class="month"><?php echo $date->format('F '); ?><?php echo $date->format('Y'); ?>
Return me the day, month and year like that : 06 September 2016
I wanted to split the date into different <p> and then to be able to customize the date and it’s working.
For the value, I use get_field with my field jour_de_levenement.
Maybe I need to put this (my div date-custom-page) before the query_post ?
Thanks a lot for your time !
Hi @snogy
I believe you can do it by using this query:
$args = array('post_type' => 'evenement',
'showposts' => 12,
'meta_key' => 'jour_de_levenement',
'meta_compare' => '>',
'meta_value' => date("Ymd"),
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
I hope this helps 🙂
You must be logged in to reply to this topic.
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 Chat Fridays”
— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 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.