Support

Account

Home Forums Add-ons Repeater Field Query on a repeater date pear (acf)

Helping

Query on a repeater date pear (acf)

  • I’m struggling with this. I a have list of date (not fixed, I can have as many date as I want) made thanks to the ACF Repeater. In my query, I want to filter by date.

    But, I have to hide some post if the date choosen is not between my 2 date fields (evenement_date_start and evenement_date_end). This is an example of my date list.

    fields

    So if I choose between 01/10/2020 and 20/10/2020, the event should not show up. But right now, it does and I can’t figure out why.

    This is my query args, my date and variable have this format “Ymd” :

        $args[] =
        ['relation' => 'OR',
            ['relation' => 'AND',
                [
                    "key" => "evenements_liste_dates_AAA_evenement_date_start",
                    "compare" => "<=",
                    "type" => 'DATE',
                    "value" => $startDate,
                ],
                [
                    "key" => "evenements_liste_dates_AAA_evenement_date_end",
                    "compare" => ">=",
                    "type" => 'DATE',
                    "value" => $endDate,
                ]
            ],
            ['relation' => 'OR',
                [
                    "key" => "evenements_liste_dates_AAA_evenement_date_start",
                    "compare" => "BETWEEN",
                    "type" => 'DATE',
                    "value" => [$startDate, $endDate],
                ],
                [
                    "key" => "evenements_liste_dates_AAA_evenement_date_end",
                    "compare" => "BETWEEN",
                    "type" => 'DATE',
                    "value" => [$startDate, $endDate],
                ]
            ],
        ];

    And my post where rewriting

    
        add_filter('posts_where', function ($query, WP_Query $wp_query) {
            if(!is_admin() && $wp_query->query_vars['post_type'] == "evenement" && !$wp_query->is_main_query()) {
                $query = str_replace("meta_key = 'evenements_liste_dates_AAA_evenement_date_start'", "meta_key LIKE 'evenements_liste_dates_%_evenement_date_start'", $query);
                $query = str_replace("meta_key = 'evenements_liste_dates_AAA_evenement_date_end'", "meta_key LIKE 'evenements_liste_dates_%_evenement_date_end'", $query);
            }
            return $query;
        }, 10, 2);
  • date fields do not store values in standard date format and should not be considered date’s for query purposes

    You’re type must be ‘CHAR’ or ‘NUMERIC’ default is fine
    your date values must be formated YYYYMMDD

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

You must be logged in to reply to this topic.

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.