Created
September 2, 2013 17:49
-
-
Save DrewAPicture/6415461 to your computer and use it in GitHub Desktop.
Update post fields (counter part to get_post_field()
This file contains hidden or 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 | |
/** | |
* Update one or more post fields | |
* | |
* @global wpdb $wpdb | |
* | |
* @param array $field Array of field/value pairs to update. | |
* @param WP_Post|int $post Post object or id. | |
* | |
* @return int|bool Number of updated rows, false on failure. | |
*/ | |
function update_post_fields( $fields, $post ) { | |
global $wpdb; | |
if ( ! is_array( $fields ) || empty( $fields ) ) | |
return; | |
if ( ! is_a( $post, 'WP_Post' ) ) | |
$post = get_post( $post ); | |
$rows = $wpdb->update( $wpdb->posts, $fields, array( 'ID' => $post->ID ) ); | |
return $rows; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment