WP_Query in admin bar breaks post editor
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.
- The topic ‘WP_Query in admin bar breaks post editor’ is closed to new replies.