[Resuelto] Create posts from existing files on server
This support ticket is created hace 5 años, 8 meses. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
I created a custom post type using Types called 'Recordings'. On the server I have a directory in /uploads that I'd like to use to generate posts from. That directory has lots of subfolders in it. For example:
I would like to be able to create a post (in the Recordings custom post type) using the title of the file, and attach the file to it (probably using a custom field).
Are you suggesting you want to scan the uploads directory and automatically generate posts from the files that are found there?
That would be a bit of a strange question.
You would need to write a custom script for that (which you would run one time only; helpfully the code snippets you can add at Toolset > Settings > Custom Code let you do so), and it's outside of our support policy to provide code in a case such as this.
I did a quick bit of Googling and think this forms the basis of what you need: enlace oculto
You would scan the uploads directory for mp3 files using the glob function which would return all the results as an array.
You would then loop over that array and create a new post (using wp_insert_post) which you update with the file URL as a custom field (using add_post_meta).
That sounds do-able.
If you are not the person to do it you would need to hire a developer (and WordPress developer, I don't think you need a Toolset developer specifically).
Let me ask this a different way, and thank you very much for finding the method!
I think I found a way to scan and import non wordpress inserted media items.
How would I use wp_insert_post (along with add_post_meta to add these posts (after the fact). Also, this would probably have to run on a cron since these files would be coming on a daily basis. So I guess the trigger would be IF a new file appears in X* directories?
Sorry I can't really give you a tutorial on how to do that. The one thing you should be aware of is that, if you register the post type and custom field with Types, then the custom field meta key (as stored in the db) is the field slug with a 'wpcf-' prefix, e.g. a custom field "audio-file" would be stored with a key wpcf-audio-file.