Created
June 21, 2018 23:37
-
-
Save NickDeckerDevs/ab3cb8969f97add111fc2e56d18f4df9 to your computer and use it in GitHub Desktop.
Export pages by parent page ID
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
| /* get the post ID -- you will edit the code below on line 14 ($new_pages[] = {your post id};) | |
| * open up the live site, edit the file: | |
| * wp-admin/includes/export.php | |
| * search for "grab a snapshot" | |
| * comment out the next line | |
| * $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" ); | |
| * add the following code right below it. Save file, run export, then un-comment | |
| * the original code and delete your inserted code | |
| */ | |
| # Export only a particular page and all its children | |
| $post_ids = array(); | |
| $new_pages = array(); | |
| $new_pages[] = 2; # Parent page ID, which we will export, along with all its children | |
| while (count($new_pages)) { | |
| $where = "WHERE post_parent IN (".join(',', $new_pages).")"; | |
| foreach ($new_pages as $np) { | |
| $post_ids[] = $np; | |
| } | |
| $new_pages = array(); | |
| $new_pages = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); | |
| } | |
| # $post_ids array now contains the pages we wish to export |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment