title: Removing Content with wp_delete_post in a Plugin with Custom Post Type
body: <p>I set up a plugin that adds a custom post type and then brings in a bunch of dummy content with wp_insert_post on activation like so:</p>
  
  <pre><code>    register_activation_hook( __FILE__, array( $this, 'activate' ) );
  public function activate( $network_wide ) {
          include 'dummycontent.php';
          foreach ($add_posts_array as $post){
          wp_insert_post( $post );
      };
  } // end activate
  </code></pre>
  
  <p>I would like to remove this content when the plugin is deactivated so I set up this function:</p>
  
  <pre><code>    register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
     public function deactivate( $network_wide ) {
          include 'dummycontent.php';
      foreach($remove_posts_array as $array){
          $page_name = $array["post_title"];
          global $wpdb;
          $page_name_id = $wpdb-&gt;get_results("SELECT ID FROM " . $wpdb-&gt;base_prefix . "posts WHERE post_title = '". $page_name ."'");
          foreach($page_name_id as $page_name_id){
              $page_name_id = $page_name_id-&gt;ID;
              wp_delete_post( $page_name_id, true );
          };
      };      
  } // end deactivate
  </code></pre>
  
  <p>It works just fine. Except because the custom post type is created with the same plugin that these two functions are run through, the post type is removed before the posts themselves can be through <code>wp_delete_post</code>. When I test these functions out without the custom post type posts are added upon activation and removed upon deactivation. So I know the problem is with the post type. Does anyone know how to work around this?</p>