Media library upload hook

I think what you need is media_upload_{$type} hook. Here’s the documentation for it: https://developer.wordpress.org/reference/hooks/media_upload_type/ There’s also an easier way to achieve a similar result, by using the filter wp_handle_upload which is really straightforward. Here’s the doc about it: https://developer.wordpress.org/reference/hooks/wp_handle_upload/ If you could provide more details about the result you want to achieve, I’ll try my … Read more

Assign multiple categories to Media Library upload

Here’s how I did it, using a form to id file and set doc type, uploading with media_handle_upload, then post-processing using the attachmentID and combo box choice from the form with wp_set_object_terms: function myFileUploader() { if (isset($_POST[‘submit’])) { require_once( ABSPATH . ‘wp-admin/includes/image.php’ ); require_once( ABSPATH . ‘wp-admin/includes/file.php’ ); require_once( ABSPATH . ‘wp-admin/includes/media.php’ ); $doctype = … Read more

wp cli media commands not working

Media is the post type (post_type=”attachment”), so most operations are done with wp post command. By default, wp post manage blog posts (post_type=”post”), therefore by fetching post IDs you must add –post_type=attachment indicating the type of posts. And to update media meta you should use wp post meta update <id> <key> <value> Your entire command … Read more