Condition is not working as desired

I have a condition that looks like this:

TODAY -> before -> Custom date from metadata.

today: {{global.date({"format":"d M Y"})}}
custom metadata date: {{dc:date:generic date="@{{dc:post:meta key="wpcf-fecha-webinar"}}" format="d M Y"}}

the date is a timestamp: 1784160000 (example)

what i want is to show the content from a date after today. it works on one of my loopers but for some reason the same exact condition doesn’t work here and puts 1 events showing correctly while another that was added today basically, showing in the same group as the passed ones!

I don’t have a good way to debug this so I ask for your help, maybe you can tell me how can I debug this in the future.

Hey @franticape,

Why the Condition is Failing

The primary issue is the date format being used for comparison: d M Y (e.g., "07 Jul 2026").

When Pro evaluates conditions like before or after on formatted date strings, it compares them alphabetically/lexicographically rather than chronologically. For example, "10 Jan 2026" might be evaluated as “before” "07 Jul 2026" simply because 1 comes before 0 or J comes before J, which leads to inconsistent and incorrect results.

The Solution

For logical comparisons in conditions, you should always compare dates using either Unix Timestamps or a chronological string format like Ymd (e.g., 20260707).

Option A: Compare using Unix Timestamps (Recommended)

Since your metadata is already stored as a timestamp, compare raw timestamps directly:

  • Today’s Timestamp: {{global.date({"format":"U"})}} (evaluates to a Unix timestamp like 1783456789)
  • Custom Metadata Timestamp: {{dc:post:meta key="wpcf-fecha-webinar"}} (no format wrapper needed if it’s already a raw timestamp)

Option B: Compare using chronological format (Y-m-d or Ymd)

If you must use date formats, use:

  • Today: {{global.date({"format":"Ymd"})}}
  • Custom Metadata: {{dc:date:generic date="@{{dc:post:meta key="wpcf-fecha-webinar"}}" format="Ymd"}}

How to Debug This in the Future

  1. Print the Raw Values: Add a temporary text element inside the looper/layout and paste your two dynamic content strings side-by-side:

    Today: {{global.date({"format":"d M Y"})} 
    Custom: {{dc:date:generic date="@{{dc:post:meta key="wpcf-fecha-webinar"}}" format="d M Y"}}
    

    This lets you inspect exactly what strings the WordPress server is comparing.

  2. Check Timezones: Ensure your WordPress timezone settings under Settings > General match your local target timezone. global.date respects the WordPress timezone setting, which can sometimes cause “today” to differ by a day if not configured correctly.

AWESOME! thank you very much! so the problem here is how the conditions are read. that is really good information!!

one more thing. this time is related to the sorting. can you tell me why if i sort the provider by the metavalue, with the same content that should be read as a timestamp. and i switch it to be sorted in an ascending matter, it shows nothing? while in descending, it does work?

Hey @franticape,

This behavior typically occurs due to how WordPress handles meta_key queries and sorting when some posts have empty or missing meta values.

Why Ascending Shows Nothing (While Descending Works)

When you sort a Query Looper Provider by meta_value_num or meta_value in Ascending (ASC) order:

  1. Empty/Missing Metadata is Sorted First: WordPress sorts database entries with NULL or empty/missing meta values to the very top/beginning of the results list.
  2. Looper Limit/Pagination Cuts Off the Valid Posts: If you have posts that do not have the webinar date meta key set (such as drafts, standard blog posts, or older events), these empty values are pulled first. If your looper has a count limit (e.g., show 5 or 10 items), the looper’s capacity is completely filled by these “empty” posts before it ever reaches the posts containing valid timestamps. Since these posts have empty dates, they might fail your display conditions, resulting in nothing showing up on the page.

When you sort in Descending (DESC) order:

  • The largest numbers (the newest future timestamps) are sorted first, pushing the empty/missing values to the very end of the list, allowing your valid events to display correctly.

How to Fix This

To prevent empty meta values from breaking the ascending sort, you need to ensure the query only retrieves posts that actually possess that meta key:

  1. If you are using a Query Builder looper provider:
    • Add a Meta Query rule: wpcf-fecha-webinar Exists (or Compare: EXISTS).
  2. If you are using a Query String looper provider:
    • Add &meta_query[0][key]=wpcf-fecha-webinar&meta_query[0][compare]=EXISTS to your query arguments.

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