Home > Mobile >  Disable custom post type
Disable custom post type

Time:09-22

I create a custom type to display different event in my agenda page. My custom type use a date field (by ACF) I order my event's grid by date (acf field)

I would like to disable automaticly (hide in the grid) the event when the event date is over.

My code :

<div class="row" id="gallerydate">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$loop = new WP_Query( array( 
'post_type' => 'calendar',
'posts_per_page' => 8,
'meta_key'  => 'date_du_concert',
'orderby' => 'meta_value',
'order' => 'DESC',
'paged'          => $paged )
);
if ( $loop->have_posts() ):
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-md-3 col-6">
<div class="cardagenda">
<?php //the_post_thumbnail('large', array('class' => 'cover-img')); ?>
<img src="<?php echo get_the_post_thumbnail_url( null, 'large' ); ?>" class="cover-img wp-post-image">
<?php if (get_field('statut')): ?>
<div class="statutagenda"><?php the_field( 'statut' ); ?></div>
<?php endif; ?>
<div class="dateagenda">
<?php the_field( 'date_du_concert' ); ?>
</div>
<div class="lieuagenda">
<?php the_field( 'lieu_du_concert' ); ?>
</div>
                        <div class="ticketagenda">
                            <?php $artiste = get_field( 'artiste' ); ?>
                            <?php if ( $artiste ): ?>
                            <?php foreach ( $artiste as $post ):  ?>
                                <?php setup_postdata ( $post ); ?>
                                <a href="<?php the_permalink(); ?>">Infos & tickets</a>
                            <?php endforeach; ?>
                            <?php wp_reset_postdata(); ?>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                <?php endwhile; ?>
                <?php wp_reset_postdata();
                endif; ?>

CodePudding user response:

Check this page https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

In your query arguments you should add something like :

'meta_key'  => 'date_du_concert',
'meta_value' => date( "Ymd" ), // change to how "date_du_concert" is stored
'meta_compare' => '>',
  • Related