Support

Account

Home Forums Add-ons Repeater Field Query and orderby repeater value

Unread

Query and orderby repeater value

  • I have a Custom Post Type called “Films“, with a Repeater field called “Showings“, which have a field “start_datetime” of type DateTime…

    I want to perform a query to get all those Films with a Showing in the next 7 days, and I want to order them by Showing’s start_datetime.

    I have this query:

    $query = new \WP_Query( array(
        'numberposts'   => -1,
        'post_type'     => 'film',
        'meta_key'      => 'showings_%_start_datetime',
        'orderby'       => 'meta_value_num',
        'order'         => 'ASC',
    
        'meta_query'    => array(
            array(
                'key'       => 'showings_%_start_datetime',
                'value'     => array( time(), strtotime( '+7 days' ) ),
                'type'      => 'NUMERIC',
                'compare'   => 'BETWEEN'
            )
        )
    ));

    This grabs all the films that have at least one showing in the next 7 days correctly, but it orders the films by the start_datetime of the FIRST showing, and I need it to order them by the start_datetime of the FIRST UPCOMING showing… Any help please?

    ——————————————————

    Example:
    FilmA has a showing today.
    FilmB has a showing tomorrow and another showing 1 year ago.

    My results will be ordered: (1) FilmB (2) FilmA, because actually FilmB is the one with a showing starting eralier (1 year ago). But I need it to be ordered (1) FilmA (2) FilmB, because FilmA is the film with the first upcoming showing (today)…

Viewing 1 post (of 1 total)

The topic ‘Query and orderby repeater value’ is closed to new replies.