Home Forums Add-ons Repeater Field Repeater field meta_query between 2 dates


Repeater field meta_query between 2 dates

  • I can’t get this to work at all, I’m trying to build into a rest_{post_type}_query but struggling to get it to work on a regular query not sure what I’m doing wrong all so I’m trying to get any results from this query between 2 dates:

    $args = array(
        'post_type' => 'tours',
        'posts_per_page' => -1,
        'meta_query' => array(
                'key' => 'linked_tours', // Name of the repeater field
                'value' => array( '20230822', '20230925' ), // Array of start and end dates
                'type' => 'DATE',
                'compare' => 'BETWEEN', // To check if the date falls within the range

    linked_tours is the name of a repeater field on the tours post type containing 2 sub_fields, a datepicker and a post object. I’m trying to return tours between 2 dates but getting no results.

    I’ve tried a few combinations on the ‘key’ that I found on the forum but none working. Sorry if this has been asked before but I haven’t found a solution and any help would be appreciated.

  • Hi John,

    Thanks for your reply, I actually had read through this before posting and couldn’t get it to work but have since managed it and figured it out.

    Thank You

  • I do not do searches on sub fields of repeaters, in fact I go out of my way to not use repeaters when I have to use the data in searches.

    When I must use a repeater for data that needs to be search then I find creative ways to not actually search the repeater. Here is a post I wrote years ago on the topic in the internet archive

    Another way to that I have done something similar is the same way that “The Events Calendar” plugin manages repeating events. There is a hidden post that represents each event. When the main post is saved then hidden child posts are added and deleted as necessary. Searches are performed on the child posts, these are used to get the parent post.

  • Thanks John, my code works now but I think I really should change it after reading that article.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.