• I have an ACF field called end_date. I am trying to query posts that have an end date after today’s date. Basically a list of upcoming events. Using this plugin, I can use the end_date ACF field as the meta key and manually type in a date for the meta value, this returns expected results. However, I would like to know if the meta value can be something like date() so it will always use the current date.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I think I have the same question. My meta key is end_date for an event. I want to query only the events, which are in the future.

    I am trying to use “current_time(‘Ymd’) as a meta value and compare “>=”, but I don’t get any results.

    Why?

    Same here. Sorry to jump in here.

    I also have ACF date field and want to show all posts that are “>=” than the current date. Could you solve the problem to compare the current date?

    Thread Starter Lane

    (@laned69)

    I discovered two problems for me: neither the ACF meta_key nor the meta_value were being inserted into the query.

    It appears that ACF is not registering the custom fields as post meta. I had to write a simple function to do that. Perhaps you might not have this problem.

    I am fine with that but the next part is kinda ugly. I added one line of code to the AQL plugin file query-loop.php. This is not ideal or recommended as any updates to the plugin may overwrite, requiring the line of code to be re-added or no longer work. Inside the foreach loop on line 23 I added:

    if ( $query['meta_value'] == "todays_date" ) { $query['meta_value'] = date( 'Ymd' ); };

    Then, in the query loop block settings I put “todays_date” as the meta_value.

    This works, but is not “proper”. And I’m sure the plugin author will have a much better way to do it.

    UPDATE: After updating to 1.4.1, I re-added same line of code and it still works.

    Thanks Lane.

    It would be nice if something like this could be done without hacking. I find the plugin great and very useful, but that is currently probably the limit.

    During my research on how to change the query loop, I came across this website and the AQL plugin was introduced at the End oft the following article. I have now done it according to this tutorial.
    https://wpfieldwork.com/modify-query-loop-block-to-filter-by-custom-field/#block-variations

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Current date as meta value’ is closed to new replies.