Skip Navigation

[Resolved] Output (AND FILTER BY) ACF date fields in Views

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to be able to search and filter Views using date fields I created in ACF.

Solution: Only simple fields like text and number can be used as filters in Views. The date format created in ACF is not compatible with the date format used by Types and Views. The only way to use these values as filters is to create new date fields in Types and transcribe the old dates into the new fields.

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by FrancoisJ6057 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1123918
Nos cours de perfectionnement.png
Nos cours de perfectionnement 2.png
Modifier la vue.png

I use ACF for some fields (as mentionned in that previous discusion: https://toolset.com/fr/forums/topic/output-acf-date-in-views/) and Minesh helped me output the dates in a "human readable format" (j F Y).

But then, I want to have a filter to narrow the results between two dates, but it doesn't work.... When a pick a date either it doens't narrow the search, or it returns nothing...

In the Query filter section, I tried Unsigned, Signed, Date, Chain, Number.... always the same result:

In the Views Search and Pagination, I have this code :

<div class="form-group et_pb_column et_pb_column_1_2">
    <div class="form-group"><strong>Départ prévu de la formation</strong><br/>
      <label>[wpml-string context="wpv-views"]entre le : [/wpml-string]</label>
      [wpv-control-postmeta field="gestion_groupe_0_date_debut" type="date" url_param="_debut1"]
      <br>
      <label>[wpml-string context="wpv-views"]et le : [/wpml-string]</label>
      [wpv-control-postmeta field="gestion_groupe_0_date_debut" type="date" url_param="_debut2"]
    </div>
  </div>

I used a similar query for another CPT, but with dates picked up in a custom toolset field.

Thanks in advance again 🙂

#1123972
Nos cours de perfectionnement3.png

One more thing 🙂

The shortcode provided in the thread https://toolset.com/fr/forums/topic/output-acf-date-in-views/ doesn't solve entirely my problem :
The shortcode provided tranform the unix timestamp in a readable format. But, if there's no date, it output the date of the present day (as shown in image)....

#1124055

But then, I want to have a filter to narrow the results between two dates, but it doesn't work..
Hi, there are a couple of issues here:
1. Only simple ACF fields are compatible with Views filters. Date is not a simple field, because dates can be represented in many different formats.
2. ACF date field values are stored in the database as a string like "20181009", but Types date field values are stored as Unix timestamps. Views date filters are designed to work with Unix timestamps like "1539043200", so the ACF date fields are ultimately incompatible with Views filters.

One solution is to create a date field in Types and translate ACF date field values into Types dates in each post, then begin editing the Types date fields in the future instead of the old ACF date fields. In your View, set up the custom filters using the new Types date field instead of the ACF field.

This is a tedious operation if you do it manually in wp-admin and there are many affected posts. A skilled developer might be able to write a script that automates this operation using PHP or MySQL, and that is probably the best approach.

#1127498

Ok thanks,