Home › Forums › Front-end Issues › How to hidden Posts, when the last date is in the past?
Hey guys.
Me again.
I have a little problem to set post-query right.
https://screenshots.firefox.com/n4znjawAULjBu4SU/localhost
As you can see: there a 4 events, each event has tickets with dates in the future or today. I want to hidden these Posts, when the last Event is in the past.
At the moment, my query looks like:
$posts_empfehlungen = get_posts(array
(
'posts_per_page'=> 4,
'post_type'=> 'event',
'post_status' => 'publish',
'meta_key' => 'termine_info',
'meta_value' => 'date',
'meta_compare' => '<',
'orderby' => 'meta_value',
'post__not_in' => array( $post->ID )
)
);
but it's wrong :/ here my complete code
<section class="row">
<?php
$posts_empfehlungen = get_posts(array
(
'posts_per_page'=> 4,
'post_type'=> 'event',
'post_status' => 'publish',
'meta_key' => 'termine_info',
'meta_value' => 'date(d.m.Y)',
'meta_compare' => '<',
'orderby' => 'meta_value',
'post__not_in' => array( $post->ID )
)
);
$query = new WP_Query( $posts_empfehlungen );
if( $posts_empfehlungen ): ?>
<?php foreach( $posts_empfehlungen as $post ):
setup_postdata( $post );
?>
<article class="col-md-6 col-lg-3 col-12"> <?php
$header_img = get_field( 'header_img' ); ?>
<?php if ( $header_img )
{ ?>
<section class="row">
<div class="col-12" style="padding: 15px">
<figure class="imgwrapper" style="height: 190px; background-image: url('<?php echo $header_img['url']; ?>'); background-position: center; background-attachment: local; background-origin: content-box; background-repeat: no-repeat; background-size: cover; ">
</div>
</section>
<?php
} ?>
<?php $slider_images = get_field( 'slider' ); ?>
<?php $slider_image = $slider_images[0]; ?>
<?php if ($slider_image)
{
?>
<section class="row">
<div class="col-12" style="padding: 15px">
<figure class="imgwrapper" style="height: 190px; background-image: url('<?php echo $slider_image['url']; ?>'); background-position: center; background-attachment: local; background-origin: content-box; background-repeat: no-repeat; background-size: cover; ">
</div>
</section>
<?php
}
else
{
//Nothing
}
?>
<?php
?>
<section class="row">
<header class="col-12">
<h4><?php the_title()?></h4>
<h5><?php the_field( 'subheadline' ) ?></h5>
</header>
</section>
<?php if ( have_rows( 'content' ) )
{ ?>
<?php while ( have_rows( 'content' ) )
{ the_row(); ?>
<?php if ( get_row_layout() == 'content_right' )
{ ?>
<section class="row" style="margin-bottom: 30px">
<article class="col-12">
<?php $excerpt = wp_trim_words( get_sub_field('text' ), $num_words = 40, $more = ' ... weiterlesen' ); ?>
<a href="<?php the_permalink($post->ID); ?>"><?php echo $excerpt ?></a>
<?php
?>
</article>
</section>
<?php }
}
}
//here are my tickets
get_template_part( 'template-parts/tmp', 'eventempfehlung-termine' );
?>
</article>
<?php endforeach; ?>
</section>
The topic ‘How to hidden Posts, when the last date is in the past?’ is closed to new replies.
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.