cptui_convert_post_type_posts

Converts post type between original and newly renamed.

Description

cptui_convert_post_type_posts( (string) $original_slug = '', (string) $new_slug = '' ); 

Parameters (2)

0. $original_slug — Optional. (string) => ''
Original post type slug. Optional. Default empty string.
1. $new_slug — Optional. (string) => ''
New post type slug. Optional. Default empty string.

Usage

  1. if ( !function_exists( 'cptui_convert_post_type_posts' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'custom-post-type-ui/inc/post-types.php'; 
  3.  
  4. // Original post type slug. Optional. Default empty string. 
  5. $original_slug = ''; 
  6.  
  7. // New post type slug. Optional. Default empty string. 
  8. $new_slug = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = cptui_convert_post_type_posts($original_slug, $new_slug); 
  12.  

Defined (1)

The function is defined in the following location(s).

/inc/post-types.php  
  1. function cptui_convert_post_type_posts( $original_slug = '', $new_slug = '' ) { 
  2. $args = array( 
  3. 'posts_per_page' => -1,  
  4. 'post_type' => $original_slug,  
  5. ); 
  6. $convert = new WP_Query( $args ); 
  7.  
  8. if ( $convert->have_posts() ) : 
  9. while ( $convert->have_posts() ) : 
  10. $convert->the_post(); 
  11. set_post_type( get_the_ID(), $new_slug ); 
  12. endwhile; 
  13. endif; 
  14.  
  15. cptui_delete_post_type( $original_slug );