$start_date = date( 'ym01' );
$end_date = date( 'ymt' );
$meta_query = array(
    'key'       => 'event_date',
    'value'     => array( $start_date, $end_date ),
    'compare'   => 'BETWEEN',
    'type'      => 'NUMERIC'
$args = array(
    'post_type'         => 'spektakle_event',
    'posts_per_page'    => -1,
    'orderby'           => 'meta_value',
    'meta_key'          => 'event_date',
    'order'             => 'ASC',
    'meta_query'        => array( $meta_query )
$the_query = new WP_Query( $args );

I used this code on CPT page-spektakle-event.php to display only this month events. But how can I make navigation to display next month or next to next month events ? Custom post type has custom field event_date with yyyymmdd format.

Or maybe simpler idea (but I don't know how to build query) that page will check what month is now and display only that events which have the same number in custom field ( i know how to make that field :D ) and navigation will be addin +1 or -1 to search through next and previous month events.... any help ?


This is not something that WordPress can easily do. You can think of pagination in WP as sliding window that shows fixed size part of one large query. It can be at start of the query or at the end, but it relies on it being same query.

This doesn't nearly work when the size and number of the page are subject to variable logic like this.

I had recently answered very similar question and recommended to use date archives. But your case is more complicated since your effective dates are in custom fields.

I would guess overall you won't be able to easily built meaningful pagination-like navigation for these. Something like faceted search might serve this better.

  • I know it won't be easy but it should be easy for people who adding events, and clear for those who search events for this or next month. I can make archive page to list this events if it will be simpler way to make navigation query. – Sebastian Melmac Jun 13 '16 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.