Title: Problem with wp_insert_post during admin-post.php
Last modified: January 31, 2021

---

# Problem with wp_insert_post during admin-post.php

 *  Resolved [Kevin Koslowski](https://wordpress.org/support/users/themadwizard/)
 * (@themadwizard)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/problem-with-wp_insert_post-during-admin-post-php/)
 * Hello there!
 * First I want do remark, that I am a really big fan of your plugin. I like how
   it seemlesly intrgrates with the core and doesn’t clutter the backend. The free
   version is already great and the paid version adds nice features that I am truly
   considering of adding to my projects. But during my experiemnts I stumbled over
   a problem, that seems to be like a bug.
 * When I try to add a custom post via `wp_insert_post()` during a custom action
   that is triggered from the backend list of my custom posts the plugin tries to
   access `get_current_screen()` during a filter for ‘pre_get_posts’. The error 
   is the following:
 * `Notice: Trying to get property 'id' of non-object in /var/www/html/wp-content/
   plugins/media-library-organizer/includes/global/media.php on line 449 Warning:
   Cannot modify header information - headers already sent by (output started at/
   var/www/html/wp-content/plugins/media-library-organizer/includes/global/media.
   php:449`
 * I can workaround this bug with the following snippet before adding the post:
 * `remove_all_filters('pre_get_posts');`
 * But the correct way of handling this I think would be, if Media Library Organizer
   would recognize the execution during an admin-post request and would not try 
   to access the current screen. Could you apply a fix for this into the main source?
 * Greetings,
    Kevin

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

 *  [wpmedialibrary](https://wordpress.org/support/users/wpmedialibrary/)
 * (@wpmedialibrary)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/problem-with-wp_insert_post-during-admin-post-php/#post-13986590)
 * Fixed in 1.3.2, releasing February 1st 2021 23:59 UTC.
 *  Thread Starter [Kevin Koslowski](https://wordpress.org/support/users/themadwizard/)
 * (@themadwizard)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/problem-with-wp_insert_post-during-admin-post-php/#post-13996769)
 * Thank you very much, the fix works like a charm! 🙂

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

The topic ‘Problem with wp_insert_post during admin-post.php’ is closed to new replies.

 * ![](https://ps.w.org/media-library-organizer/assets/icon-256x256.png?rev=3377647)
 * [Media Library Organizer – Folders, File Manager & Media Categories](https://wordpress.org/plugins/media-library-organizer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-library-organizer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-library-organizer/)
 * [Active Topics](https://wordpress.org/support/plugin/media-library-organizer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-library-organizer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-library-organizer/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Kevin Koslowski](https://wordpress.org/support/users/themadwizard/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/problem-with-wp_insert_post-during-admin-post-php/#post-13996769)
 * Status: resolved