PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Auto Expire Post

  1. domainguerilla
    Member

    Hello guys. I have a form setup for users to create posts via the frontend of the website which works great. I installed the plugin Post-Expirator to set posts up to automatically expire after a certain period of time, which also works great when I personally publish a post via the backend of Wordpress, but the problem arises when a post is publish via Gravity Forms.

    Both plugins do everything they're supposed to do with no conflicts and regardless of user role. They just don't seem to be talking to each other when the post is published. I even thought is was a matter of the timestamp variables and I created custom field in the GF forms and used hooks to dynamically populate them with the corresponding variables used by Post-Expirator.

    I know you all really don't go into too much depth troubleshooting 3rd-party plugins, but I am all out of tries and was hoping the solution might be something you may have ran across before and is a simple add_filter/add_action or something. Thanks guys..

    Posted 12 years ago on Thursday October 13, 2011 | Permalink
  2. What does post-expirator look for to know to expire a post? A custom field? And, in what format is the date? If that's how the plugin works, you will need to ensure that Gravity Forms writes the same custom field, with the same exact key, and the exact same date format. Have you done all that?

    Posted 12 years ago on Thursday October 13, 2011 | Permalink
  3. domainguerilla
    Member

    Hey Chris! Looks like you were absolutely right, and I had managed to miss creating the single custom field in my form that the submitted post would have needed for the Post-Expirator plugin to work. So here's the add_filter that made it work...

    add_filter("gform_field_value_timedelete", "populate_timedelete");
    function populate_timedelete(){
    //Add 3 days to current time
    $time_delete = time()+259200;
    return $time_delete;
    }

    Now while I have you, I wasn't able to comprehend this thread when it comes to populating a custom field based on the choices from a drop-down or the examples on "form object" and "entry object". The same custom field value from above (the one I named "timedelete" that's being populated with the variable "$time_delete") is the one I wanted to be dynamically populated, presumably by using an IF statement based on one of three choices from the drop down. I don't understand how to retrieve the drop-down values so I could use them in my function. Here is what I think my code should somewhat look like (minus what I'm missing)...

    add_filter("gform_field_value_timedelete", "populate_timedelete");
    function populate_timedelete(){
    //Replacing this commented line with the code to retrieve drop down values
    if (drop down choice ONE is true){
           //Drop down Choice One is 3 days, add three days to date
    	$time_delete = time()+(60*60*24*3);
    	return $time_delete;
    } else if (drop down choice TWO is true) {
           //Drop down Choice Two is 7 days, add seven days to date
    	$time_delete = time()+(60*60*24*7);
    	return $time_delete;
    }
    else if (drop down choice THREE is true) {
           //Drop down Choice three is 14 days, add fourteen days to date
    	$time_delete = time()+(60*60*24*14);
    	return $time_delete;
    }
    }

    Any pointers?

    Posted 12 years ago on Thursday October 13, 2011 | Permalink
  4. If you're still having any trouble with this... this snippet should do the trick:

    http://pastie.org/2909923

    Posted 12 years ago on Wednesday November 23, 2011 | Permalink
  5. Oh man that couldn't have been easier!!!!
    Thanks, guys!

    Posted 12 years ago on Tuesday December 13, 2011 | Permalink

This topic has been resolved and has been closed to new replies.