Created
March 16, 2022 15:48
-
-
Save BrandonKnudsen/840ef4fc902b1ff9a9cce7066918b1ce to your computer and use it in GitHub Desktop.
Wordpress Move posts to new post type by category
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 | |
| 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