Home › Forums › Add-ons › Repeater Field › Sort by date in repeater field
Hi,
My repeater is “dates” with sub value “date_spectacle”
this query returns posts of a given month, but only on the first sub value of the repeater (dates_0_date_spectacle)
How could i do look for for in all rows ? dates_%date_spectacle ???
(ACF date return value set on ‘d-m-y’)
Thanks
$today = date("d/m/Y");
$themonth=substr($today, 3,2);
$args = array (
'post_type' => 'spectacle',
'numberposts' => -1,
'post_status'=>'publish',
'meta_key' => 'dates_0_date_spectacle',
'meta_value' => '[0-9]{4}' . $themonth . '[0-9]{2}',
'meta_compare' => 'REGEXP',
);
Elliot please would you have an idea ?
thanks
i also try to get all spectacle where date >= date today but i don’t know how
Hi @Pipoulito
Posts can only be ordered by 1 custom field, so it is not possible to order by multiple sub fields fortunately.
Hi @Pipoulito
On second thought, it may be possible, however, the performance would be quite slow.
Please read over this doc to get some starter code:
http://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/
Thanks
E
thanks Elliot, but i sometimes seen this expression with % : dates_%_date_spectacle
does no it means all fields ?
thanks
Hi @Pipoulito
Sorry, but I don’t understand your last question.
The %
is a wildcard and will match any string which allows it to work with the repeater field incremental numbers for sub field keys
ok thanks so would you mean this code should show
only EVENT where month=current month ?
thnaks
$today = date("d/m/Y");
$themonth=substr($today, 3,2);
$args = array (
'post_type' => 'EVENT',
'meta_key' => 'dates_%_date_EVENT',
'meta_value' => '[0-9]{4}' . $themonth . '[0-9]{2}',
'meta_compare' => 'REGEXP',
);
Hi @Pipoulito
You will also need to hook into the posts_where filter and add some extra code to allow for the meta_key to match via LIKE.
Checkout the following doc for more info
http://www.advancedcustomfields.com/resources/how-to-query-posts-filtered-by-custom-field-values/#example-5
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.