Greetings Leonardo!
Thank you so much for your positive feedback. We are really happy that you are getting good use of our plugin.
We are about to release a big update to this plugin with a few new cool features. We are also releasing a pro version, so stay tuned.
To answer your first question, you will need add a acf field for the expiration date, then you need to add a custom query to your elementor posts widget to exclude posts that have an expired date. I will add this code soon.
Regarding your second question, in the widget settings, under the “permissions” tab, put in [author] and that will make the form visible only to the user who posted.
Hello you should place this code in your functions.php file in your child theme. Then enter “my_custom_filter” in the posts widget in the Elementor editor. This is the custom query name and you can make it whatever you want as long as it exactly matches in both the widget and in the action hook below
add_action( ‘elementor/query/my_custom_filter’, function( $query ) {
//Get the current date
$today = date(‘Ymd’);
// Get current meta Query
$meta_query = $query->get( ‘meta_query’ );
// Append our meta query
$meta_query[] = [
‘key’ => ‘expire_date’, //replace this with your ACF field name
‘compare’ => ‘>=’,
‘value’ => $today,
];
$query->set( ‘meta_query’, $meta_query );
} );
Hi Shabti, thank you so much for your effort in helping me, truly appreciated.
I tried what you said; I have copied the snippet and pasted it in my child theme functions.php
I have changed the filter name to hide_past_events_filter
I have set “end_date” as my ACF field name, since that is my event’s end date and I want the event to expire on that date.
I have then copied hide_past_events_filter and pasted it in the “Query ID” field in my posts elementor widget. However I am still able to see all the events, also the expired ones, and the filter seems to knot work.
Do you have any idea on why this is not currently working? Am I forgetting something?
Thank you again for your support.
Hello, in the code snippet you have to change the query key to whatever your ACF field is. Did you change the query key to ‘end_date’?
Yes, I did.
Here is how my code looks:
add_action( ‘elementor/query/hide_past_events_filter’, function( $query ) {
//Get the current date
$today = date(‘Ymd’);
// Get current meta Query
$meta_query = $query->get( ‘meta_query’ );
// Append our meta query
$meta_query[] = [
‘key’ => ‘end_date’, //replace this with your ACF field name
‘compare’ => ‘>=’,
‘value’ => $today,
];
$query->set( ‘meta_query’, $meta_query );
} );
I think the problem is that I copied and pasted this in this forum as plain text and not code, try the code below… Also try changing the return format in the date-picker field to YMD. Are you using datetime picker by any chance?
add_action( 'elementor/query/hide_past_events_filter', function( $query ) {
//Get the current date
$today = date('Ymd');
// Get current meta Query
$meta_query = $query->get( 'meta_query' );
// Append our meta query
$meta_query = [
'key' => 'end_date', //replace this with your ACF field name
'compare' => '>=',
'value' => $today,
];
$query->set( 'meta_query', $meta_query );
} );
Hi Shabti,
I tried what you suggested. I copied and pasted your latest code, and I alse changed the return format to Ymd in the ACF field options. It did make sense actually cause the return format was set to a totally different format.
However I still can’t see any difference. The post widget it’s still showing all the events, even if I set the Query ID to hide_past_events_filter
An I am using just a JQuery Date Picker, not a DateTime Picker.
Ok I did some testing on my site. It seems the Elementor docs were at fault (its okay we’ll forgive them cause theyre usually so great). I based my code on their page which talks about this,
You basically have to change this
$meta_query = [
'key' => 'end_date', //replace this with your ACF field name
'compare' => '>=',
'value' => $today,
];
to this
$meta_query = [
[
'key' => 'end_date',
'value' => $today,
'compare' => '>=',
]
];
Hi Shabti,
thank you so much! It is working perfectly now.
I’ll be patiently waiting for the PRO version!
In the meantime, I will be opening another topic since I am facing another issue regarding taxonomy input from the front end and I do not want to make the discussion longer here.
Thank you again for your help, hope this will help other users, super appreciated.
Leonardo.
I’m really happy to help any time!
Version 2 of our plugin will let you create an edit taxonomy term too and it is set to be released in the coming days