Skip to content

Instantly share code, notes, and snippets.

@BrandonKnudsen
Created March 16, 2022 15:48
Show Gist options
  • Select an option

  • Save BrandonKnudsen/840ef4fc902b1ff9a9cce7066918b1ce to your computer and use it in GitHub Desktop.

Select an option

Save BrandonKnudsen/840ef4fc902b1ff9a9cce7066918b1ce to your computer and use it in GitHub Desktop.
Wordpress Move posts to new post type by category
<?php
ob_start( );
$args = array(
'category_name' => 'category-slug',
'posts_per_page' => -1
);
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$my_post = array(
'ID' => get_the_ID(),
'post_type' => 'post_type_name',
);
//echo '<br>'.get_the_ID();
echo wp_update_post( $my_post );
}
}
$output = ob_get_clean( );
echo $output;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment