ACF between two dates on options page

I have a WordPress site where I’m using the Options Page plugin. On that page, I’ve created a repeater field (called “husmanslunch”) that has a datepicker field (called “date”) in it. It’s used to enter one meal per day of the week and then I’m trying to list each meal for the current week. Here’s my go at it:

<?php
$mon = date('Ymd', strtotime('monday this week'));
$sun = date('Ymd', strtotime('sunday this week'));

$args = array(
  'post_type'   => 'husmanslunch',
  'posts_per_page'  => -1,
  'meta_query'    => array(
   array(
      'key' => 'date',
      'value' => array( $mon, $sun ),
      'compare' => 'BETWEEN'
    )
  )
);

$wp_query = new WP_Query( $args );

while( $wp_query->have_posts() )
{
  $wp_query->the_post();
  the_sub_field('name');
}

?>

I’m guessing that the line with post_type might be incorrect as well as the the_sub_field (trying to get the name from the same object that has the date field. But since “husmanslunch” is located in the ACF option page, I’m not quite sure how to target it.

Read More

Any ideas to help me out (this doesn’t print anything)?

Thanks in advance.

Related posts

Leave a Reply

1 comment

  1. As it’s a option page and you’re probably trying to fetch it from a template-file, you need to specify the ID of which page you’re fetching acf-fields from – in this case a option-page, so it’s:

    $repeater = get_field(‘husmanslunch’,’option’);
    $repeater

    $repeater = get_field('husmanslunch','option'); // the second param could be a pageID also, but in you case you want the 'option' for the option page
    
    // and you could do:
    <?php while ( have_rows('husmanslunch') ) : the_row(); ?>
    <?php the_sub_field('name'); ?>
    <?php endwhile; ?>