If you want to move content to post_content for search it is very different than if you want to move content that can be displayed on another site.
For search, all you need is the data of the field to be in the content and not formatted in any way. On the other hand, importing it into a site without ACF and being able to use it on another site without editing is completely different.
The first is easier than the second.
For the second you will need to loop through all of the fields when saved in the same way that you display the pages/posts on the front end of the site. You need to build all the html and content and then insert it into the post. This will be like building the front end of the site twice. More than likely this process will time out the admin of your site when saving posts if they have a large number of fields.
There are two methods for the first, you could do the looping and put all the content into the content. This first method will have the same problems as trying to build the html content. The second method is to directly query the database to get all of the meta content from the post in just a few queries and then insert it. This is faster, but more complicated.
Something else that you need to deal with is the fact that flex fields change and ACF does not update removed fields. Looping through the content and building it the same way as is done for the front end of the site avoids putting this stale data into the content. But then your back to dealing with the time involved to do the work. On the other hand, doing DB queries means that you need to find a way to remove that stale data or ignore it so that it’s not inserted into the content.
Anyway, those are pretty much your options and I wanted you to have those before I gave a link to a plugin. This is a plugin that I’m working on to deal with the search issue and it is not meant to deal with the formatting issue in any way. It also only deals with text, textarea and wysiwig fields at this time because it’s all I am really concerned about. I probably won’t add other types of fields unless I have a need to. I feel that these 3 field types added to content will resolve 90% of the search problem. You are free to try it out or to look at my code to see how I’m doing this. It uses the second method of doing direct DB queries. I’ll let you read the rest there https://github.com/Hube2/acf-to-content
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.