Title: Function hook: get folder id
Last modified: May 30, 2021

---

# Function hook: get folder id

 *  Resolved [Trevsweb](https://wordpress.org/support/users/trevsweb/)
 * (@trevsweb)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/function-hook-get-folder-id/)
 * Hi looking to add a hook to my functions.php that can catch when an attachment/
   image is added to the system.
 * trying to get it to log the folder id of the attachment while its uploading.
   
   ive tried add_attachment but it only comes back with -1
 * tried wp_attachment_folder and wp_rml_get_object_by_id but these only work when
   editing the file not when it first gets uploaded
 * basically I just want to pass which folder RML is storing the file in to the 
   post that is being created into its meta. when i can get a valid folder id the
   rest should be fine with my code.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Trevsweb](https://wordpress.org/support/users/trevsweb/)
 * (@trevsweb)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/function-hook-get-folder-id/#post-14499533)
 * found it in the code. wondering if there is an easier method
 * $folderidrlm = isset($_REQUEST[‘rmlFolder’]) ? $_REQUEST[‘rmlFolder’] : null;
 * hope that helps other people I just used the add_attachment hook
 * another question. there’s cover image support for the folders how do you access
   it?
 *  Plugin Contributor [Matthias Günter](https://wordpress.org/support/users/mguenter/)
 * (@mguenter)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/function-hook-get-folder-id/#post-14505951)
 * Hi [@trevsweb](https://wordpress.org/support/users/trevsweb/) !
 * Thanks for your message.
 * You can use something like this:
 *     ```
       add_action('add_attachment', function($post_id) {
           $folderId = wp_attachment_folder($post_id);
           if (is_rml_folder($folderId)) {
               $coverImageId = get_media_folder_meta($folderId, 'coverImage', true);
           }
       }, 11 /* This is important so your hook is executed after RML */);
       ```
   
 * See also:
    - [https://docs.devowl.io/real-media-library/php/index.html#method_wp_attachment_folder](https://docs.devowl.io/real-media-library/php/index.html#method_wp_attachment_folder)
    - [https://docs.devowl.io/real-media-library/php/index.html#method_get_media_folder_meta](https://docs.devowl.io/real-media-library/php/index.html#method_get_media_folder_meta)
 * If you have any further questions, feel free to ask!
 * Regards,
    Matthew 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Function hook: get folder id’ is closed to new replies.

 * ![](https://ps.w.org/real-media-library-lite/assets/icon-256x256.gif?rev=2293211)
 * [Real Media Library: Media Library Folder & File Manager](https://wordpress.org/plugins/real-media-library-lite/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/real-media-library-lite/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/real-media-library-lite/)
 * [Active Topics](https://wordpress.org/support/plugin/real-media-library-lite/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/real-media-library-lite/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/real-media-library-lite/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Matthias Günter](https://wordpress.org/support/users/mguenter/)
 * Last activity: [4 years, 11 months ago](https://wordpress.org/support/topic/function-hook-get-folder-id/#post-14505951)
 * Status: resolved