Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Delete all Advanced Post Types Order (APTO) sorts.
- *
- * WARNING:
- * This permanently removes all APTO sort configurations,
- * their child sort views, and the associated sort indexes.
- */
- function my_delete_all_apto_sorts() {
- global $APTO;
- if ( empty( $APTO ) || empty( $APTO->functions ) )
- return false;
- // Get all sort holders.
- $sorts = get_posts(
- array(
- 'post_type' => 'apto_sort',
- 'post_status' => 'any',
- 'posts_per_page' => -1,
- 'post_parent' => 0,
- 'fields' => 'ids',
- 'suppress_filters' => true,
- )
- );
- if ( empty( $sorts ) )
- return true;
- foreach ( $sorts as $sort_id ) {
- // Get all child sort views belonging to this sort.
- $sort_views = get_posts(
- array(
- 'post_type' => 'apto_sort',
- 'post_status' => 'any',
- 'posts_per_page' => -1,
- 'post_parent' => $sort_id,
- 'fields' => 'ids',
- 'suppress_filters' => true,
- )
- );
- // Delete child sort views and their sort indexes.
- foreach ( $sort_views as $sort_view_id ) {
- wp_delete_post( $sort_view_id, true );
- $APTO->functions->delete_sort_list_from_table( $sort_view_id );
- }
- // Delete the parent sort holder.
- wp_delete_post( $sort_id, true );
- }
- return true;
- }
Advertisement