WordPress.org

Ready to get started?Download WordPress

Forums

Postie
[resolved] Set date in 'postie_post_before' filter (9 posts)

  1. mjpg
    Member
    Posted 11 months ago #

    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/

  2. Wayne Allen
    Member
    Plugin Author

    Posted 11 months ago #

    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'

  3. mjpg
    Member
    Posted 9 months ago #

    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

  4. mjpg
    Member
    Posted 9 months ago #

    In debug, it is showing:

    [post_status] => publish

  5. mjpg
    Member
    Posted 9 months ago #

    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?

  6. mjpg
    Member
    Posted 9 months ago #

    Would postie_post_after be of any help to me?

  7. Wayne Allen
    Member
    Plugin Author

    Posted 9 months ago #

    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.

  8. mjpg
    Member
    Posted 8 months ago #

    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.
  9. Wayne Allen
    Member
    Plugin Author

    Posted 8 months ago #

    Thanks for sharing your code!

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.