I want to re-publish all previously published products of a custom post type. Let's say the post type is "events"
This is what I was thinking something like this:
$args = array(
'post_type' => 'events',
'post_status' => 'publish', // get only published posts?
'posts_per_page' => -1
);
$posts = new WP_Query( $args );
if ( $posts -> have_posts() ) {
while ( $posts -> have_posts() ) {
wp_publish_post(NEED TO GET ID)
}
}
wp_reset_query();
The thing I can't figure out how to get the id in the loop or how to get just published posts (took an educated guesss)
*Edited *
$args = array(
'post_type' => 'events',
'post_status' => 'publish', // get only published posts?
'posts_per_page' => -1
);
$posts = new WP_Query( $args );
if ( $posts->have_posts() ) {
while ( $posts->have_posts() ) {
$posts->the_post();
wp_publish_post($post->ID)
}
}
