Title: ACF Date &#8211; Loop between
Last modified: August 24, 2016

---

# ACF Date – Loop between

 *  Resolved [renan_santos](https://wordpress.org/support/users/renan_santos/)
 * (@renan_santos)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/acf-date-loop-between/)
 * I am not being able to loop between a date range from 2 acf date fields.
    Could
   you please help me? i tried using acf_date and acf_date_2 and also field with
   compare.
 * Also tried this:
    [loop type=”page” parent=”123″ acf_date=”data_de_inicio” value
   =”past” orderby=”data_de_inicio” order=”ASC”] [if acf_date=”data_de_termino” 
   value=”future”] …
 * My date fields are stored as Ymd.
 * [https://wordpress.org/plugins/custom-content-shortcode/](https://wordpress.org/plugins/custom-content-shortcode/)

Viewing 15 replies - 1 through 15 (of 15 total)

 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990299)
 * If I understand correctly, you would like to use two ACF date fields from the
   current post, and get pages within the date range. I set up a test and was able
   to do it like this:
 *     ```
       [pass fields="acf_date_1, acf_date_2"]
         [loop type="post" count="15" after="{ACF_DATE_1}" before="{ACF_DATE_2}"]
           [field title] - [field date]
         [/loop]
       [/pass]
       ```
   
 *  Thread Starter [renan_santos](https://wordpress.org/support/users/renan_santos/)
 * (@renan_santos)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990300)
 * Thank you very much for your answer.
    I’m sorry. I was’nt much clear on my explanation.
 * I want to show events that are occurring. So, i need to get posts that TODAY 
   is in the range of ACF_DATE_1 and ACF_DATE_2.
    Each of these posts have ACF_DATE_1
   and ACF_DATE_2 (start and end date).
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990306)
 * I see, thank you for clarifying. I tried this, and found that [loop] was not 
   recognizing the second date field query. I corrected this in the newest plugin
   update.
 * So, I believe you’re looking for something like this:
 *     ```
       [loop type="page" field="data_de_inicio" value="today" compare="<=" field_2="data_de_termino" value_2="today" compare_2=">=" date_format="Ymd"]
       ```
   
 * A shorter version would be:
 *     ```
       [loop type="page" field="data_de_inicio" value="past" field_2="data_de_termino" value_2="future" date_format="Ymd"]
       ```
   
 * The difference between these two is that _value=”past”_ will match past dates
   _not including today_.
 *  Thread Starter [renan_santos](https://wordpress.org/support/users/renan_santos/)
 * (@renan_santos)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990308)
 * Thank you very much! 😀
    past and future works fine. By the way, i cannot get
   > or <. They are being escaped as > and < I could use another loop to find fields
   equal to today, but that is not much elegant…
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990311)
 * Sure, I made another update so you can do this:
 *     ```
       [loop .. value="past and today" ..]
       ```
   
 * I also added a check in case comparison value is escaped. This is probably due
   to using the Visual editor.
 *  Thread Starter [renan_santos](https://wordpress.org/support/users/renan_santos/)
 * (@renan_santos)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990312)
 * Wow!
    Wonderful. Thank you very much Eliot! 😀
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990320)
 * Great, I’m glad it works. It was a good chance to improve support for ACF date
   fields.
 * I used the date field comparison in a recent project, where I had to list current
   events (today and future) and past events (not including today) in separate sections.
   That’s when I added these new parameters – and that’s why “future” includes today
   and “past” doesn’t.
 * In your case, because it’s a range between two dates, it makes sense to include
   today in both. I hope it’s not too confusing, I updated the documentation for[
   loop] to describe this feature.
 *  Thread Starter [renan_santos](https://wordpress.org/support/users/renan_santos/)
 * (@renan_santos)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990390)
 * `[loop type="curso" field="data_de_termino" value="past" date_format="Ymd" orderby
   ="data_de_inicio" order="ASC"]`
    This code filters the content correctly, but
   the order is incorrect!
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990391)
 * How about: `orderby="field" key="data_de_inicio"`..?
 *  Thread Starter [renan_santos](https://wordpress.org/support/users/renan_santos/)
 * (@renan_santos)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990392)
 * Sorry for that.
    Thank you!
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990393)
 * 🙂
 *  Thread Starter [renan_santos](https://wordpress.org/support/users/renan_santos/)
 * (@renan_santos)
 * [11 years ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990407)
 * Hi Eliot.
    I’m trying everything i can imagine to make it work, but have not 
   been succeeded yet. It works fine when i list previous or future events, but 
   when i try to list events in between (where today is between or equal start and
   end dates) it does not work.
 * The following code (and similar attempts) does not work:
 * `[loop type="curso" field="start_date" value="today" compare="<=" field_2="end_date"
   value_2="today" compare_2=">=" date_format="Ymd" orderby="field" key="data_de_inicio"
   order="ASC"]`
 * The following code shows all events:
 * `[loop type="curso" field="start_date" value="past and today" field_2="end_date"
   value_2="future" date_format="Ymd" orderby="field" key="data_de_inicio" order
   ="ASC"]`
 * Any idea?
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [11 years ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990408)
 * If you could give me some time, I’ll set up a test to see why it’s not working
   as expected. I’ll let you know when I find something.
 *  Thread Starter [renan_santos](https://wordpress.org/support/users/renan_santos/)
 * (@renan_santos)
 * [11 years ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990409)
 * Wonderful!
    Thank you very much, Eliot!
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [11 years ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990410)
 * I found the problem: I recently rewrote how multiple fields are queried, and 
   date format was only being applied to the first field. I fixed this in the newest
   update (2.2.4) so your code should work as expected now. Please let me know if
   that works.

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘ACF Date – Loop between’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-content-shortcode_766976.svg)
 * [Custom Content Shortcode](https://wordpress.org/plugins/custom-content-shortcode/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-content-shortcode/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-content-shortcode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-content-shortcode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-content-shortcode/reviews/)

 * 15 replies
 * 2 participants
 * Last reply from: [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/acf-date-loop-between/#post-5990410)
 * Status: resolved