• Resolved mjpg

    (@mjpg)


    Using Postie v1.5.15

    I’m using post_date as a way of setting a post_meta field.

    However, setting $post[‘post_date’] seems to set the post to scheduled.

    This is my code:

    // set the expiry date
    	$expiry_date = strtotime($post['post_date']); // Get date from post
    	$post['post_date'] = date('Y-m-d H:i:s', (time() - 2*60*60) ); // re-set post date to now.
    	add_post_meta( $post['ID'], '_expiration-date', $expiry_date );

    Should I set the post date to empty or null?

    http://wordpress.org/plugins/postie/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Wayne Allen

    (@wayneallen-1)

    Why are you changing $post[‘post_date’]? It should already be set correctly. If you want to force it to be the current date & time set it to’0000-00-00 00:00:00′

    Thread Starter mjpg

    (@mjpg)

    Thanks for your reply.

    The problem I am having is that posts are being set to ‘Status: Scheduled’.

    I am sending this type of email:

    Post text here
    tags: bbs
    date: Nov 11, 2013
    status: publish
    :excerptstart
    Excerpt text here
    :excerptend

    and processing it with the following, using postdate for a Post Expiration field and then attempting to re-set.

    function add_custom_taxonomy_postie_post_function($post) {
    
    	// Check for categories and use in type
    	check_post_set_taxonomy($post,'post_category','type');
    
    	// Check for tags and use to set region
    	check_post_set_taxonomy($post,'tags_input','region');
    
    	// set the expiry date
    	$expiry_date = strtotime($post['post_date']); // Get date from post
    	$post['post_date'] = '0000-00-00 00:00:00'; // re-set post date to now.
    	add_post_meta( $post['ID'], '_expiration-date', $expiry_date );
    
    	return $post;
    }

    Any ideas why the post is not being published?

    Is the date already being set and hence the scheduled?

    Thanks

    Thread Starter mjpg

    (@mjpg)

    In debug, it is showing:

    [post_status] => publish

    Thread Starter mjpg

    (@mjpg)

    I just tried without
    date: Nov 23, 2013
    set in the email and it published.

    So it is setting the date that triggers the scheduled which I know is the correct Postie action.

    The post is being set with ‘post_status’ set as ‘future’. It does not seem to honour the:

    // re-set post status
    	$post['post_status'] = 'publish';

    in my function.

    The question is then: how do I re-set the post status to ‘publish’ from:
    postie_post_before?

    Thread Starter mjpg

    (@mjpg)

    Would postie_post_after be of any help to me?

    Plugin Author Wayne Allen

    (@wayneallen-1)

    Yes, that may help but you will need to call wp_update_post
    http://codex.wordpress.org/Function_Reference/wp_update_post

    I think what is happening is that WordPress sees a future date so it is changing the status to pending. It may not be possible to have a published post with a future date.

    Thread Starter mjpg

    (@mjpg)

    Note – this now applies to v1.5.16 running under WP3.7.1

    Thanks Wayne.

    postie_post_before and wp_update_post were not needed (and did not work).

    The fix turned out to be unsetting BOTH $post[‘post_date’] AND $post[‘post_date_gmt’].

    The final working code was:

    function add_custom_taxonomy_postie_post_function($post) {
    
    	// Check for categories and use in type
    	check_post_set_taxonomy($post,'post_category','type');
    
    	// Check for tags and use to set region
    	check_post_set_taxonomy($post,'tags_input','region');	
    
    	// set the expiry date
    	$expiry_date = strtotime($post['post_date']); // Get date from post
    	add_post_meta( $post['ID'], '_expiration-date', $expiry_date );
    
    	// re-set post date to stop WordPress setting post staus to future (scheduled)
    	unset($post['post_date']);
    	unset($post['post_date_gmt']);
    
    	return $post;
    }
    
    add_filter('postie_post_before', 'add_custom_taxonomy_postie_post_function');
    
    Thanks for all your help and a great plugin.
    Plugin Author Wayne Allen

    (@wayneallen-1)

    Thanks for sharing your code!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Set date in 'postie_post_before' filter’ is closed to new replies.