• Resolved unav4ila8le

    (@unav4ila8le)


    Hi!
    First, I wanted to say I am really satisfied with this plugin, it truly covers everything I need in terms of fronted dynamics. Super happy with it.
    The only thing I cannot figure out is how to allow users from the front end to set an expiration date for the post they are submitting. In particular, I am using this plugin to allow users to submit their events, however, as we know events need to expire after the date is passed. Is there anything I can do to add this option? Maybe some kind of “magical” PHP snippet? (BTW I am not super familiar with php)

    Also I would appreciate to know if there is a way to assign authors to the posts submitted from the frontend; some of the users that submit the posts are logged in and I would like to set them as author automatically.

    Thank you in advance for your kind support.

    Leonardo.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Shabti Kaplan

    (@shabti)

    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.

    Plugin Author Shabti Kaplan

    (@shabti)

    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 );
    } );

    Thread Starter unav4ila8le

    (@unav4ila8le)

    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.

    Plugin Author Shabti Kaplan

    (@shabti)

    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’?

    • This reply was modified 5 years, 4 months ago by Shabti Kaplan.
    Thread Starter unav4ila8le

    (@unav4ila8le)

    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 );
    } );
    Plugin Author Shabti Kaplan

    (@shabti)

    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 );
    } );
    Thread Starter unav4ila8le

    (@unav4ila8le)

    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.

    Plugin Author Shabti Kaplan

    (@shabti)

    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' => '>=',
    	]
    ];
    Thread Starter unav4ila8le

    (@unav4ila8le)

    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.

    Plugin Author Shabti Kaplan

    (@shabti)

    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

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Is there a way to set a post expiration date from the frontend?’ is closed to new replies.