Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Pippin Williamson

    (@mordauk)

    I’d recommend setting up a cron job that looks for expired posts and then updates them accordingly.

    Take a look at WP Cron: http://codex.wordpress.org/Category:WP-Cron_Functions

    Thread Starter danielchopkins

    (@danielchopkins)

    That’s what I ended up doing.

    add_action( 'update_job_status', 'job_status_function' ); 
    
    function my_activation() {
    	if (!wp_next_scheduled('update_job_status')) {
    		wp_schedule_event( time(), 'daily', 'update_job_status' );
    	}
    }
    
    add_action('wp', 'my_activation');
    
    function job_status_function() {
    	global $post;
    	$args = array('post_type' => 'job', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC');
    	$jobs = new WP_Query($args);
    	if ($jobs->have_posts() ) {
    		while ($jobs->have_posts()) {
    			$jobs->the_post();
    			if ( get_post_meta( $post->ID, 'pw_spe_expiration', true ) ) {
    				$post = array( 'ID' => $post->ID, 'post_status' => 'draft' );
    				wp_update_post($post);
    				echo "hello";
    			}
    		}
    
    	}
    }

    I agree with Daniel. Would be perfect if the user can choose what to do with the posts upon expiration, such as: Change status to ‘draft’ / Move to trash, etc.

    Setting up cron jobs is outside the reach of the majority.

    Great plugin, all the same!

    jamzth

    (@jamzth)

    I ended up adding a function that checked if an “Expired” category existed (created it if so), added the “Expired” category (as well as prepended “Expired:”), and changed the status to “Draft”. Interested in the code?

    Also, there was an issue at line 52 of metabox.php that needed adjusting did that as well.

    I’ll add the code if requested. Gotta run now.

    @jamzth
    Would love to learn about your solution to this if you can share it.

    @lmartins
    I went ahead and forked his github to add custom functionality and other things. Check out the code here: https://github.com/jamzth/Expired

    Cool, thanks for sharing.
    Have you considered submiting a PR to the original repo instead?

    Plugin Author Pippin Williamson

    (@mordauk)

    Pull requests are always welcome 🙂

    Sorry, I’ve been meaning to do that. Honestly, this is the first time that I’ve had an opportunity to fix a bug for a project to even commit. I’m fairly new to the pull request stuff. I’ll get it out to you soon, hopefully.

    There, I think that is everything in the pull request

    I’m working on similar right now.

    @jamzth – I just saw your plugin on GH, nice work. It looks like you run wp_update_post on ‘the_title’ filter. I’m curious when this actually runs. I don’t think it will be automatic, but will require a user to hit a page on the website, right? I like this solution better.. but curious of its reliability.

    @pippin – I’m nervous about the reliability of cron jobs. Do you have thoughts on this pull request? And/or do you anticipate including it? I’m trying to decide which route to go here.

    @luis – howdy brother! We keep crossing paths!

    Hi guys. Is this plugin fully working now with above mentioned modifications? Thank you

    Plugin Author Pippin Williamson

    (@mordauk)

    It has not been updated yet.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Change post status after post expires’ is closed to new replies.