Home › Forums › General Issues › Displaying posts by date picker, and hiding expired. › Reply To: CPT pagination chaining, displaying posts by date picker.
I found a simple script which allowed me to show upcoming events.
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$the_query = new WP_Query( array(
'post_type' => 'events',
'posts_per_page' => 4,
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'start_date',
'paged' => $paged
) );
$current_header = '';
while ( $the_query->have_posts() ) :
$the_query->the_post();
# get the datum for this post
$temp_date = get_post_meta( get_the_ID(), 'start_date', true );
if (strtotime($temp_date) > strtotime('now')){
if ( $temp_date != $current_header ) {
$current_header = $temp_date;
include 'item-archive.php';
}?>
<?php } endwhile;?>
I also removed the pagination chaining because I couldn’t get it to work with this code.
I have one tester event that has expired, just to ensure its not showing expired events. I have it set to 4 post per page for testing, however on page 1 it only shows 3 posts, like the hidden event is still being counted.
I’ve been searching for a good solution for this all day, however I can’t find anything that will make it work.
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!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 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.