• Resolved Emielb

    (@emielb)


    Hello,

    Thanks for this great plugin!

    I am trying to show on my custom post type “event” archive page only posts that are upcoming events.

    My event custom post type has a repeater meta box eventdates with a single text field “eventdate”, where I set the dates of a single event (an event can have multiple dates).

    In my functions.php file I have the following query:

    add_action( 'pre_get_posts', 'custom_query_vars' );
    function custom_query_vars( $query ) {
      if ( !is_admin() && $query->is_main_query() ) {
        if ( is_post_type_archive('event') ) {
          $query->set( 'posts_per_page', -1 );
          $query->set( 'orderby', 'eventdate' );
          $query->set( 'meta_key', 'eventdate' );
          $query->set( 'order', 'ASC' );
          $query->set( 'meta_query', array( 
                         'key' => 'eventdate',
                         'compare' => '>=',
                         'value' => '2018-09-13'
                    )
                 );
        }
      }
      return $query;
    }

    This functions works fine for filtering events based on the first date, but if the first date is in the past, the event custom post doesn’t show anymore, even if there are other eventdate values in the future.

    How can I enhance my function for getting the eventdate values of all the dates I put in my repeater meta box?

    Thank you!

    • This topic was modified 6 years, 2 months ago by Emielb.
    • This topic was modified 6 years, 2 months ago by Emielb.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Filter posts depending on a repeater meta box field value’ is closed to new replies.