Fix for WordPress 4.1 front page “Not Found” error (from Stealth Publish plugin).

This is a public service announcement for anyone else who runs WordPress straight from SVN trunk and found their site broken after upgrading recently (probably after svn update took their site across the WordPress 4.1 boundary), such that instead of showing recent posts on the front page, you would see only this message:

Not Found.

Sorry, but you are looking for something that isn’t here.

Meanwhile, in your site’s Apache HTTPD error log, you’d see something like this:

  [Wed Nov 12 10:11:43 2014] [error] [client 74.92.190.113]              \
  WordPress database error You have an error in your SQL syntax;         \
  check the manual that corresponds to your MySQL server version         \
  for the right syntax to use near 'EXISTS '' ) \n                       \
  OR \n ( mt1.meta_key = '_stealth-publish' AND CAST(mt1.meta_value' at  \
  line 2 for query SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts \
  LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id            \
  AND wp_postmeta.meta_key = '_stealth-publish' )  LEFT JOIN wp_postmeta \
  AS mt1 ON ( wp_posts.ID = mt1.post_id ) WHERE 1=1                      \
  AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish'  \
  OR wp_posts.post_status = 'private') AND ( \n  ( wp_postmeta.post_id   \
  IS NULL AND CAST(wp_postmeta.meta_value AS CHAR) NOT EXISTS '' ) \n    \
  OR \n  ( mt1.meta_key = '_stealth-publish'                             \
  AND CAST(mt1.meta_value AS CHAR) != '1' )\n) GROUP BY wp_posts.ID      \
  ORDER BY wp_posts.post_date DESC LIMIT 0, 10 made by                   \
  require('wp-blog-header.php'), wp,                                     \
  WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts,       \
  referer: http://www.rants.org/wp-admin/customize.php?theme=kisk

The problem turned out to be an obsolete workaround in the stealth-publish plugin. This patch, which removes one line of code, fixed it for me:

  --- wp-content/plugins/stealth-publish/stealth-publish.php
  +++ wp-content/plugins/stealth-publish/stealth-publish.php
  @@ -154,7 +154,6 @@
                                          'relation' => 'OR',
                                          array(
                                                  'key'     => '_stealth-publish',
  -                                               'value'   => '', // This is needed to work around core bug #23268
                                                  'compare' => 'NOT EXISTS',
                                          ),
                                          array(

I haven’t analyzed this in depth, but here’s what I think is going on:

The workaround implemented by that line (that is, setting ‘value’ explicitly albeit only to the empty string, in order to get the right SQL result) is what’s recommended by WordPress bug #23268. However, that bug was fixed in changeset 27689, which (confusingly to those of us not accustomed to development involving multiple SVN trees, yikes) made it to http://core.svn.wordpress.org/trunk in r27528:

  ------------------------------------------------------------------------
  r27528 | wonderboymusic | 2014-03-24 14:57:15 -0500 (Mon, 24 Mar 2014) | 10 lines
  Changed paths:
     M /trunk/wp-includes/meta.php
  
  When using `meta_query` in a `WP_Query`, passing `NOT EXISTS` or `''`
  to `compare` should not require `value` to be set. The resulting SQL
  should then produce the appropriate `OR` clause for existence of
  non-existence after passing the query to the `$key_only_queries` stack
  internally.
  
  Adds unit tests.
  
  Props chrisguitarguy, for the original patch.
  Fixes #23268.
  
  
  Built from https://develop.svn.wordpress.org/trunk@27689
  
  ------------------------------------------------------------------------

Okay, so the bug was fixed in WordPress core, and when I updated, I got the fix.

Unfortunately, the stealth-publish plugin hasn’t gotten the memo yet. That plugin’s latest version is 2.4, and hasn’t been updated since January 2014 — a couple of months before the relevant WP core bugfix. And the workaround in the code is now not only unnecessary, but actually causes an SQL syntax error — which is probably reasonable, since passing a value doesn’t really make sense in a NOT EXISTS test. It’s just that anyone who was using the workaround needs to stop doing so immediately.

I hope that stealth-plugin is still being maintained by its author. It’s hard to tell right now because the stealth-publish home page is currently down for maintenance:

Temporarily down for maintenance. Check back later.

So I’m publishing the patch here, to save other people time.

Leave a Reply

Your email address will not be published. Required fields are marked *

Rants.org Comments Policy

× three = twenty one