Skip to content

Instantly share code, notes, and snippets.

@hearvox
Created January 31, 2017 01:03
Show Gist options
  • Save hearvox/ff635df4ba43245b9361e7a0d1aaa81d to your computer and use it in GitHub Desktop.
Save hearvox/ff635df4ba43245b9361e7a0d1aaa81d to your computer and use it in GitHub Desktop.
<?php
/* Update postdate for all post in a category */
// Get IDs of all posts in a category.
$args = array(
'category_name' => 'cat-name',
'fields' => 'ids',
);
$query = new WP_Query($args);
// Update meta for all IDs.
$meta_id = 0;
if ( $query->have_posts() ) {
foreach( $query->posts as $post_id ) {
$meta_id = update_post_meta( $post_id, 'meta-key-name', 'Meta Value');
// Print ID and returns.
// echo "$post_id - $meta_id\n";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment