Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active March 30, 2017 14:24
Show Gist options
  • Save tommcfarlin/3de0a26bbddc867f88a82def270a483b to your computer and use it in GitHub Desktop.
Save tommcfarlin/3de0a26bbddc867f88a82def270a483b to your computer and use it in GitHub Desktop.
<?php
// First, update the post using the available WordPress API.
wp_update_post( $post );
/**
* If the post status attribute of the post that was just updated
* maintains the 'publish' post setatus, then manually update the
* database column.
*/
if ( 'publish' === $post->post_status ) {
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"
UPDATE $wpdb->posts
SET post_status = '%s'
WHERE ID = %d
",
'publish',
$post->ID
)
);
}
<?php
$event_post->post_date_gmt = gmdate( 'Y-m-d H:i:s', $event_post->post_date_gmt );
wp_update_post( $event_post );
<?php
if ( 'attachment' !== $post_type ) {
if ( 'publish' == $post_status ) {
$now = gmdate('Y-m-d H:i:59');
if ( mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false) ) {
$post_status = 'future';
}
} elseif ( 'future' == $post_status ) {
$now = gmdate('Y-m-d H:i:59');
if ( mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false) ) {
$post_status = 'publish';
}
}
}
<?php
$post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );
<?php
if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) {
if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
$post_date_gmt = get_gmt_from_date( $post_date );
} else {
$post_date_gmt = '0000-00-00 00:00:00';
}
} else {
$post_date_gmt = $postarr['post_date_gmt'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment