public
Last active

Change FeedWordPress behavior to reset post_date_gmt to now

  • Download Gist
gistfile1.aw
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?php
/**
* For the FeedWordPress posts that are published on import, set the
* publication timestamp to now (instead of the datetime in the feed)
*/
add_filter( 'syndicated_item_published', 'fwpx_syndicated_item_published' );
function fwpx_syndicated_item_published( $ts ) {
return time();
}
/**
* Reset FeedWordPress' behavior of setting the post_date_gmt
* Only do this where the guid is different than our existing site and for 'pending' posts
* We want editors to be able to "Publish Immediately", instead of publish at the syndicated post's publication time.
*/
add_filter( 'update_syndicated_feed_completed', 'fwpx_update_syndicated_feed_completed' );
function fwpx_update_syndicated_feed_completed( $import_id ) {
global $wpdb;
 
// Get all of the syndicated posts that haven't yet been published
$query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status='pending' AND guid NOT LIKE %s;", '%' . site_url() . '%' );
$post_ids = $wpdb->get_col( $query );
 
foreach( $post_ids as $post_id ) {
$wpdb->update( $wpdb->posts, array( 'post_date_gmt' => '0000-00-00 00:00:00' ), array( 'ID' => $post_id ) );
}
};

Thanks Daniel. I've added this to feedwordpress/posts-page.php (probably very brutal/inelegant act, but) it works for new posts! However, when the posts are syndicated, they turned to "scheduled" again.

Trialing & erring. Appreciate if you may help.

@junechan
Does you fixed this issue?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.