I wrote a plugin that accepts files via Wordpress and saves them outside of the server. Now I would like to save the metadata as normal in Wordpress, as if the file were on the server. Is there a hook for this that calls wp_insert_attachment or do I have to do it manually using the $wpdb variable? When I try to include /var/www/html/wp-admin/includes/file.php with require_once, I get a lot of errors and can not access wp_ functions.

I am grateful for any help

  • Tough to answer this without any code. If you're successfully saving elsewhere then you should be able to generate the URL to the file and so you should be able to save that to the DB. Commented Feb 10, 2021 at 19:28
  • I have a URL as a return value. The data are just in an S3 memory. The question is exactly how do I get this data into the database. Is there a hook in Wordpress for this or do I have to do it via WPDB? What code is as necessary to be able to better answer to the question?
    – Benjamin
    Commented Feb 16, 2021 at 10:04
  • update_meta_data() is what you'd need, but you'd need to hook it into the process of adding it to WordPress so that when it gets uploaded and added to S3 it then also records the URL. Commented Feb 16, 2021 at 17:36

1 Answer 1


After a long search, I finally found the error. It is necessary to use

require "/path/to/wordpress/wp-load.php";

to enable wordpress functions in scripts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.