Home Forums Add-ons Repeater Field Sort by repeater using wildcard


Sort by repeater using wildcard

  • Hi

    I’m in a serious pinch here. I’m using ACF with the repeater field.
    In the repeater field, there is a field named “date” and a field named “lieu” (location in french)

    I want to get the last three items from date based on a specific location (it’s a number).

    The first part works as I added a posts_where filter to accept “LIKE” statements for those fields:

    function my_posts_where( $where )
        $where = str_replace("meta_key = 'lieu_et_date_%_date'", "meta_key LIKE 'lieu_et_date_%_date'", $where);
        $where = str_replace("meta_key = 'lieu_et_date_%_lieu'", "meta_key LIKE 'lieu_et_date_%_lieu'", $where);
        return $where;
    add_filter('posts_where', 'my_posts_where');

    But to get the last 3 items, I would need to sort by date based on the meta key matching the “WHERE” statement. What I need is to know the wildcard’s “%” value.

    Here is my code:

    $args = array(
                    'post-type' => 'post',
                    'posts_per_page' => 3,
                    'meta_query' => array(
                            'key' => 'lieu_et_date_%_date',
                            'value' => time(),
                            'compare' => '>'
                            'key' => 'lieu_et_date_%_lieu',
                            'value' => $loc,
                            'compare' => '='
                    'orderby' => 'meta_value_num',
                    'meta_key' => 'lieu_et_date_0_date',
                    'order' => 'ASC'
    $query = new WP_Query($args);

    Notice the “0” in “meta_key” used for sorting. THAT’s my problem.
    It will sort using the first field (0) but it doesn’t always correspond to the “$loc” value.
    Any ideas?
    Any help is greatly appreciated.

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

The topic ‘Sort by repeater using wildcard’ is closed to new replies.