Automatically hide a post after expiration date is reached

I’m using Bricks Builder with ACPT Pro to create a basic “Special Offers” page. Each offer (cpt) has an expiration date field (mm/dd/yyyy date format, can also be set to yyyy-mm-dd if needed).

I want the Query Loop to:

  • Show offers that are not expired, but have an expiration date (completely hidden once expiration date is reached. is it hidden from the HTML source?)

  • Show offers with no expiration date (displayed indefinitely)

What is the recommended way to do this in Bricks with ACPT Pro? Can it be done in the Query Loop with conditions?

Each offer card is simple: Heading, image, content box (text/bullet points), and a CTA button. I’ve created a query loop to display the cards on the page. My only solution at the moment is to have a toggle switch, and turn them on/off manually, which is a headache if I forget to hide it in time. I tried condition for {acpt_offers_info_expiration} (tried different settings: <=, >=, ==, etc.) {current_date} and then “or” for second condition for blank expiration dates. Also tried through Query loop with a custom meta query for info_expiration. The offers with expiration dates won’t hide.

You need a meta query here, where the date formats match e.g. as Y-m-d, which allows proper sorting and filtering. Check what is returned from custom fields etc.

I tried doing it through a query loop, but it hides everything on the front-end.

I’ve set ACPT Pro’s date format to yyyy-mm-dd. The only time it shows the cards is if I remove the {current_date …} completely. I also tried using Conditions instead of Meta Query, but that didn’t work either.

Anyone familiar with ACPT and how I can get this working? I think the meta key is correct, because that’s the format I use for the toggle switch (info_toggle) instead of the full {acpt_offers_info_expiration}.

I use ACF with a condition to hide expired stuff.

To check your output of your keys just put them in a text element and see whats rendered.

This is how i got the condition on acf field working:

Using conditions, the info doesn’t budge. I set them as {acpt_offers_info_expiration:Y-m-d} >= {current_date:Y-m-d} OR {acpt_offers_info_expiration:Y-m-d} == (none), and they still both show up no matter what. Tried changing to a paste date too…

try outputting those keys {acpt_offers_info_expiration:Y-m-d} and {acpt_offers_info_expiration:Y-m-d} inside a textfield to see what is rendered and if they work and are in Y m d order.

Im not familiar with acpt but maybe if you use a numeric or date field or so it might do someting to it like format it a certain way.

Why do you have two meta queries, remove the last or change it to exists, then you can use it for sorting.

Instead of leaving the “Meta value” field empty in the second part of the meta query put {echo:__return_empty_string} in there. Make sure to whitelist the __return_empty_string function as described here.

1 Like

Thank you, that fixed it.

I added {echo:__return_empty_string} to second meta key for posts which don’t have an expiration date, and set it to EXISTS. I then created the following snippet, and made it apply just to the offers page:

//Whitelist snippet
add_filter( 'bricks/code/echo_function_names', function() {
    if ( is_page('/special-offers/') ) {
        return ['__return_empty_string'];
    }
    return [];
});
1 Like

Can you you this plugin ?

This plugin allows you to automatically set an expiration date for your posts, ensuring they are managed efficiently over time.

When a post reaches its expiration date, it is automatically moved to draft, making it no longer visible on the front end but still available for editing or future publication.

1 Like

Thanks for the heads up! I didn’t know this plugin existed. I’ve tested it, and it works as well.