This guide walks you through the process of extracting WordPress group data from your database and formatting it for import as guided tours using WP All Import.
Overview
The workflow consists of three main steps:
Database Query - Extract group data from WordPress database
Data Export & Import - Export to CSV and import into Google Sheets
Data Formatting - Clean and format post IDs for WP All Import
Step 1: Database Query (phpMyAdmin)
What it does
Extracts all groups from your WordPress database along with their associated content (post IDs).
Instructions
Open phpMyAdmin and select your WordPress database
Go to the SQL tab
Paste and execute the following query:
SELECT p.ID as group_id, p.post_title as group_title, p.post_name as group_slug, REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(pm.meta_value, 'a:', ''), 's:4:', '' ), 's:3:', '' ), '"', '' ), ';', '|' ) as post_ids_pipe_separated FROM wp_posts p JOIN wp_postmeta pm ON p.ID = pm.post_id WHERE p.post_type = 'group' AND pm.meta_key = 'content' ORDER BY p.ID;
Query Explanation
Selects groups (custom post type 'group')
Joins with postmeta table to get the 'content' field
Cleans up serialized PHP data by removing common prefixes
Replaces semicolons with pipes for easier processing
Orders results by group ID
Step 2: Export and Import to Google Sheets
Export from phpMyAdmin
After running the query, click Export at the bottom of the results
Choose CSV format
Download the file to your computer
Import to Google Sheets
Open Google Sheets
Create a new spreadsheet or open existing one
Go to File > Import
Upload your CSV file
Configure import settings as needed
Import the data
Step 3: Data Formatting in Google Sheets
Identify the Data Column
Locate the column containing the post IDs data. This column will contain partially cleaned serialized data that needs further processing.
Apply Formatting Formulas
Formula 1: Extract 4-digit Post IDs
In an empty column (e.g., column E), apply this formula to extract 4-digit post IDs:
=TRIM(SUBSTITUTE(REGEXREPLACE(D2,".*?s:4:""(\d{4})""","$1|")," ",""))
What it does:
Uses regex to find 4-digit numbers in quotes
Replaces matches with the number followed by a pipe (|)
Removes extra spaces
Formula 2: Remove Trailing Characters
In the next column (e.g., column F), apply this formula to clean up the final format:
=LEFT(E2,LEN(E2)-3)
What it does:
Removes the last 3 characters (typically "|||" or similar trailing artifacts)
Gives you clean pipe-separated post IDs
Apply to All Rows
Select the cell with your first formula (E2)
Copy the formula down to all rows with data
Repeat for the second formula in column F
Copy the final results and paste as values to preserve the formatting
Step 4: Prepare for WP All Import
Final Data Format
After applying both formulas, you should have clean data in this format:
1234|5678|9012
This pipe-separated format is ideal for WP All Import to process multiple post IDs for guided tours.
Using with WP All Import
Export your final Google Sheets data as CSV
In WP All Import, map the cleaned post IDs column to your guided tour tour contnet post IDs field
Troubleshooting
Common Issues
Empty results: Check that your post type is actually 'group' and meta key is 'content'
Malformed data: The original data might be serialized differently - adjust the REPLACE functions as needed
Formula errors: Ensure you're referencing the correct column (D2, E2, etc.)
Data Validation
Check that post IDs are 4 digits (or adjust regex pattern if different)
Verify that pipe separation is working correctly
Confirm all groups have been extracted
Notes
This process assumes WordPress serialized data in a specific format
Post IDs are assumed to be 4 digits - modify the regex
\\d{4}if your IDs are different lengthsAlways backup your database before making changes
Test the import process with a small batch first
Support
If you encounter issues with the data format or need to modify the queries for your specific setup, consider the structure of your serialized data and adjust the REPLACE functions accordingly.
Comments
0 comments
Please sign in to leave a comment.