I have two sections with the same fields. I want to move entries from one section into the other section. There is this post but its there a better way in Craft 4?
1 Answer
This can be done using the resave/entries
console command along with the --set
and --to
option flags.
craft resave/entries --section sourceSectionHandle --set sectionId --to "=destinationSectionId"
This resaves all the entries in the section whose handle is 'sourceSectionHandle' and then uses the --set
and --to
flags to define the destination section ID of the entries, which will move them from the source section to the destination section as they're resaved.
You can find out the ID of the destination section you want to move the entries to by checking the URL in CP > Settings > Sections and edit the section. The URL looks like this:
https://yoursite.local/admin/settings/sections/11
In this example, the section ID is 11
, so the resave command would look like this:
craft resave/entries --section sourceSectionHandle --set sectionId --to "=11"