Support » Plugins » Hacks » WP_Query in admin bar breaks post editor

  • Hello,

    I’ve written a plugin that, among other things, adds a custom menu to the Admin Bar. This menu uses a custom WP_Query object to retrieve a list of a specific custom post type, and then builds a menu from that list.

    I’m finding that when the WP_Query object returns posts, it breaks the post editor. Here’s what it does:

    • Shows “Auto Draft” for the post title
    • Shows the permalink as “”, where “CPT” is the slug of the custom post type, and “####” is an ID number.

    The above occurs when attempting to add a new post, and also when attempting to edit an existing post. Note that I am trying to edit a normal post, and not the custom post type in question.

    Here’s the code that I’m using to add the custom menu:

    Here’s a screenshot of the menu that is created:

    Here’s a screenshot of what I see when I click on “All Posts” or the edit link for an existing post (note: don’t be fooled by the word “Story” in the screen capture. I have simply filtered the post labels):

    Here’s a screenshot of what I see if I disable the menu item, or if the WP_Query in the menu does not return any posts of the custom post type:

    My main question is this: Is this issue due to something that I’m doing incorrectly in my code? Or is this possibly a bug in WordPress? I have spent some time digging through the WordPress code for the /wp-admin/post-new.php page, and I can’t see how a call to WP_Query is causing this odd behavior.

    I’ve tried to provide all of the information that I can, but of course if anything is not clear, please don’t hesitate to ask for clarification.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    Hi JPry, thanks for the added info in the related thread. You say you narrowed down the source of the problem. Can you elaborate?

    Since it’s not a plugin conflict, and lacking any more information and being unable to replicate the problem, I can only speculate. It still looks like a cache corruption to me, though what might be causing it is difficult to say, I don’t even know which operations write to it.

    Use get_posts instead, using the WP_Query admin is a no go since it will overwrite the object.


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP_Query in admin bar breaks post editor’ is closed to new replies.