if ( $posts->have_posts() ) {
while ( $posts->have_posts() ) {
$posts->the_post();
wp_publish_post($post->ID)
}
}
That should do it. You need the call to the_post
to walk through the post set properly. It also sets up the $post
object.
That should set all of the posts to ‘publish’, which is what wp_publish_post
does. I guess I am not sure what you mean by “re-publish”. Possibly you mean “alter the publication date”. To do that you need to use wp_update_post
and change the post_date
and post_date_gmt
.
if ( $posts->have_posts() ) {
while ( $posts->have_posts() ) {
$posts->the_post();
wp_update_post(array('ID'=>$post->ID,'post_date'=>'','post_date_gmt'=>''))
}
}
Setting the dates to nothing will cause it to default to “now”– just tested that.
If you are trying to get these to show up again in a news feed, that still won’t do it. You have to edit the guid
for that but doing so is highly discouraged.
Also, I’d recommend you name your variable something other than $posts
. WordPress uses that name. You are clobbering the default variable.