Hello,
I'm having a problem with the permalink slug being stored when publishing. Once you type in a title and tab off, it often fails creating the permalink and returns the ugly parameter URL instead, with no option of editing. Sometimes clicking "Save As Draft" fixes it by forcing it to try again, but sometimes that results in the post just falling back into All Posts as a draft.
I think I know what may be causing, but I'm stuck on a solution.
When you type in a title, then tab off it, that's when the bug is occurring. At this moment, two AJAX calls are made, one after another to /blog/wp-admin/admin-ajax.php. On our Stage and Production boxes, the latency on this script becomes rather large while it's looking up the id and creating slug. When this fails, it's not saving the slug into the DB.
I think this hang up is causing the issue.
The closest hack I've come up with to solve this is to add this code (it's really hacky).
+++ wp-admin/includes/post.php (working copy)
function get_sample_permalink($id, $title = null, $name = null) {
- $post = &get_post($id);
+ // Try looking for the post by its id 10 times before giving up.
+ for ($i = 1; $i <= 11; $i++) {
+ $post = &get_post($id);
+ if ( $post->ID ) break;
+ // Sleep for 0.25 seconds
+ usleep (250000);
+ }
+
if ( !$post->ID )
return array('', '');
This stopped the problem on QA, but not in stage, so it's not a complete hack.
It appears the communication between my desktop and the WordPress Admin UI is faster than the communication between the WordPress instance and its database. In most environments, the WP and DB are on the same host, so WP <-> DB communication is very fast, but our setup is making this communication slower. This isn't as much of a concern on the frontend, since we'll be caching, but it's making post publish fail once out of ever 5 attempts.
Any thoughts on a code solution to the problem?