ACF Repeaters to create weekly class schedule

Hello,

I’m working with nested loopers and ACF field repeaters to create a schedule page of circus training classes. I can create tables for various class types (e.g. beginner, advanced) easily enough using query builders and dynamic content looper providers but I’d also like to create a weekly schedule that:

  1. Displays classes for each week day (e.g. Monday); and
  2. Orders the classes chronologically for each respective day.

To get only Monday classes to display I’ve applied conditions to the DIV containing the Dynamic Content Looper Provider {{dc:acf:post_field field=“times”}} which is also set as a Looper Consumer. The conditions on the nested DIV element are:

Provider Output is not empty
and
{{dc:looper:field key="day_of_week"}} is Monday

Monday classes are displaying however there’s also empty rows happening in the Looper. I’ve trawled through numerous threads about this issue but can’t pinpoint where the Monday schedule setup is wrong. Is there something I’ve missed here?

The next issue is how to get the Monday classes to display chronologically.

I’ve added query string to the top-level Looper Provider (see below) to attempt to get the outputs to filter by the ACF repeater’s ‘start_time’ field but realise the query may not be quite right.

post_type=class&post_status=publish&ignore_sticky_posts=1&posts_per_page=-1&meta_key={{dc:looper:field key="start_time"}}&meta_type=TIME&orderby=meta_value_num&order=asc

Is filtering on a top-level looper provider using a repeater that’s on the next nested (dynamic content) provider possible?

I’ll include a secure note with the site info. Any advice would be greatly appreciated.

Thanks,
Rachel

Hello Rachel,

Thanks for the very detailed post information. Your condition {{dc:looper:field key="day_of_week"}} is Monday should be added to the Looper Consumer to avoid any empty space. So far, you are on the right track.

Best Regards.

Hello @Ruenel,

The condition was already applied to the (nested DIV) Looper Consumer and there’s still empty space. I’ve tested reconfiguring the Looper Providers and Consumers, and there is a Provider Output is not empty condition applied to the top level Provider - no joy. Any advice?

And can you please advise on the 2nd part of my enquiry: how to get Monday classes to display chronologically. Can an (orderby meta value) string query be applied to a top-level looper provider if the meta value is a repeater field that’s in a nested (dynamic content) provider?

Thanks,
Rachel

Hello Rachel,

You should be using a different query argument. More like this:

$meta_query[] = array(
    'key' => 'times_0_day_of_week',
    'value' => 'Monday',
    'compare' => '='
);

$args = array(
  'post_type' => 'class',
  'orderby'    => 'title',
  'order'      => 'ASC',
  'meta_query' => $meta_query
);

This would give you:
post_type=class&orderby=title&order=ASC&meta_query%5B0%5D%5Bkey%5D=times_0_day_of_week&meta_query%5B0%5D%5Bvalue%5D=Monday&meta_query%5B0%5D%5Bcompare%5D=%3D

Please check out the demo in the secure note below.

Thank you @ruenel,

Your query argument makes much more sense and has saved the day! Really appreciate the demo page too. I’ll recreate this and adjust to build the whole classes schedule.

You are most welcome, Rachel.

Sorry @ruenel, I’m stuck again on the orderby part of the array. I’m wanting to sort the results by start time rather than class title. I’ve tried using the custom field to define orderby –

'orderby' => 'times_0_start_time',

This does change the order but not based on the start times and I’m wondering if it’s because start_time somehow needs to be defined as ‘type’ => ‘DATETIME’ so that the results sort correctly. How do I add another meta_query into the same $args array or am I missing something obvious with orderby?

Hi again @ruenel, I’ve figured it out and a simple fix. The orderby needed to be specified as a number value and the field added as a meta key:

$meta_query[] = array(
    'key' => 'times_0_day_of_week',
    'value' => 'Monday',
    'compare' => '='
);

$args = array(
  'post_type' => 'class',
  'orderby'    => 'meta_value_num',
    'meta_key' => 'times_0_start_time',
  'order'      => 'ASC',
  'meta_query' => $meta_query
);

So the string query outputs as:

post_type=class&orderby=meta_value_num&meta_key=times_0_start_time&order=DESC&meta_query%5B0%5D%5Bkey%5D=times_0_day_of_week&meta_query%5B0%5D%5Bvalue%5D=Monday&meta_query%5B0%5D%5Bcompare%5D=%3D

If I’m still misunderstanding something please let me know but grateful to have got a working schedule structure.

Thanks again for your assistance to figure this out.

Glad to hear you’ve figured a fix.

Hello again,

Seeking further advice on the query string that’s targeting nested ACF repeater values in the class schedule:

First day of classes in the weekly schedule (Monday) looks good because the meta query key is calling the 1st row of the ACF repeater but when creating the loopers for a later day in the week (e.g. Wednesday), classes that have instances (repeater rows) that are earlier in the week won’t show and there’s empty rows in the schedule.

I’ve attempted to edit the meta query and argument to include arrays of the 3 repeater field rows for the meta query meta key and orderby meta key to accomodate up to 3 instances of a class each week:

$meta_query[] = array(
    'key' => array ('times_0_day_of_week', 'times_1_day_of_week', 'times_2_day_of_week'),
    'value' => 'Monday',
    'compare' => '='
);

$args = array(
  'post_type' => 'class',
  'orderby'    => 'meta_value_num',
    'meta_key' => array ('times_0_start_time', 'times_1_start_time', 'times_2_start_time'),
  'order'      => 'ASC',
  'meta_query' => $meta_query
);

This at least gets classes to display but it’s still not quite right. Is there a better way to target the ACF repeater fields in this string query?

I’m attaching screenshots of the ACF repeater setup and how this looks for one of the circus classes that runs on multiple days in case this is helpful.

Hey Rachel,

Working with Query Strings is an advanced WordPress topic which we can’t provide further guidance as part of theme support. We can guide you further in our One Single Platform support.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.