I am using WordPress CLI to import pages from one site to another.
On the new site we rebuild 200 pages using ACF, these pages have the same slug as the original pages.
I have 700 pages to import in total.
is there anyway to ignore the rebuilt/duplicate pages by slug(or anything) when running the CLI command? I can't find anything in the docs here https://developer.wordpress.org/cli/commands/import/#examples . I was hoping someone else may have found a solution
wp import myoldsite.wordpress.2022-09-15.002.xml
CodePudding user response:
I am assuming the 200 pages are not sequential otherwise the skip option would have worked. In your case there is no option to ignore based on slugs or anything else.
If you know some shell scripting you can use this to check the page in a loop :
wp query --format=count --post_type=page --post_status=publish --post_name=example-page
and if the page exists skip it otherwise import it .
#!/bin/bash
# List of pages to import
pages=(page1 page2 page3 page4)
# WordPress username and password
wp_user="admin"
wp_pass="password"
# Iterate through list of pages
for page in "${pages[@]}"; do
# Check if page already exists
if wp --quiet post list --user="$wp_user" --password="$wp_pass" --field=ID | grep -q "$page"; then
echo "Skipping $page, it already exists"
else
# Import page
echo "Importing $page"
//code to import
fi
done
Good luck !