Home › Forums › Add-ons › Repeater Field › 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(
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.
see the section on this page about searching sub fields
https://www.advancedcustomfields.com/resources/query-posts-custom-fields/
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 https://web.archive.org/web/20190814230622/https://acfextras.com/dont-query-repeaters/
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.
You must be logged in to reply to this topic.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.