Viewing 8 replies - 1 through 8 (of 8 total)
  • I am looking for guidance with this one also.
    WP All Import can fill in the custom field of ‘Expiration date’, but need some help figuring out the Cron Job hook, just started digging.
    I hop hs1972 maybe had some luck?

    thanks.-crssp

    Thread Starter hs1972

    (@hs1972)

    Sorry Crssp still pulling my hair out with this one I’m afraid…will update if I find anything but I’m quite new to all this so could take a very long time!

    In my case I’m going to use the AutoPrune plugin.
    It seems to just check against the time stamp of the post, and for example if it’s a week old (or whatever depending on your settings) it moves the post to trash or deletes them.

    Check this one out:
    https://www.ads-software.com/plugins/auto-prune-posts/

    Any solution for WP All import???

    Hi all, I’m also having this issue. I’ve got WP All Import to import an expiration date to my posts, but it seems this expiration date doesn’t activate unless I first go into every post and save it first.

    @benattenborough did you manage to figure out a solution? I have the same issue. I can get it to import properly but it won’t work unless I uncheck and recheck the box and update.

    Hi, so off the top of my head here’s what I think is happening:
    All Import just updates the values in the post expirator fields, but that is not enough to actual set an expiration time with the system.
    I believe that when you save the post expirator settings it adds a chron job to the system which is activated at the time you set. But as I said WP All Import doesn’t add the chron job, it just updates the fields.

    Now thinking about it WP All Import has function editor. So it may be possible to write some code to add a chron job at the same time as updating the Post Expirator fields.

    I’m going to have a look into this and if I get anywhere I’ll update the forum.

    Okay I think I have a solution:

    WP All Import has it’s own actions which you can hook functions to. By using this you can schedule cron events. (See https://www.wpallimport.com/documentation/advanced/action-reference/).

    So I’m experimenting by putting this in my functions.php:

    
    add_action('pmxi_saved_post', 'post_saved', 10, 1);
    
    function post_saved($id) {
       $expiration_date = get_post_meta($id, 'expiration-date', true);
       if ($expiration_date) {
          $opts = array();
          $opts['expireType'] = 'delete';
          $opts['id']         = $id;
          echo "Setting expiration date for post " . $id . " to the timestamp " . $expiration_date;
          _scheduleExpiratorEvent( $id, $expiration_date, $opts );
       } else {
          echo "No expiration date set for post " . $id . ". Exiting";
       }
    }
    

    The code above fetches the ID of the current post and uses that to get the expiration date.
    Provided the post has an expiration date the system will call _scheduleExpiratorEvent which is a function from WP Post Expirator. This in turn with both set the meta and hook to WP’s own cron scheduler, which should then schedule the event.

    You’ll notice I’m echoing out some messages – these will appear on your import history logs at the top of each import if things are set up correctly.

    You could also modify the code above to fetch the expire type meta field and pass it along as an option, if you want to select how the post is expired.

    I’ve only done a quick test on this but it seems to work. By the way you can find out if cron jobs have been set with a neat little plugin called WP Crontrol https://en-gb.www.ads-software.com/plugins/wp-crontrol/ I’d recommend it for checking if your cron events have been setup. One tip though cron events will be under tools > cron events and schedules under settings > cron schedules. I found that a little confusing!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WP All Import’ is closed to new replies.