WP_Query in admin bar breaks post editor (3 posts)

  1. Jeremy Pry
    Posted 2 years ago #


    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 "http://example.com/?post_type=CPT&p=####", 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: https://gist.github.com/JCPry/5127193

    Here's a screenshot of the menu that is created: http://screencast.com/t/B10xRgSeWsbU

    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): http://screencast.com/t/B10xRgSeWsbU

    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: http://screencast.com/t/NzNh5SVlM

    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.

  2. bcworkz
    Posted 2 years ago #

    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.

  3. wycks
    Posted 2 years ago #

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

    Ref: http://core.trac.wordpress.org/ticket/18408

Topic Closed

This topic has been closed to new replies.

About this Topic