Created
June 6, 2012 20:21
-
-
Save danielbachhuber/2884507 to your computer and use it in GitHub Desktop.
Change FeedWordPress behavior to reset post_date_gmt to now
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) ); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.