Title: Database error: querying non-existent table
Last modified: July 24, 2021

---

# Database error: querying non-existent table

 *  Resolved [goldeneagle](https://wordpress.org/support/users/goldeneagle/)
 * (@goldeneagle)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/)
 *     ```
       Hi
       I’m loading the Custom Related Posts functionality manually by including the following php in my theme template
       if ( function_exists( 'echo_crp' ) ) { echo_crp(); }
       In general, everything seems to be working fine at the front end (great plugin by the way) but I’m getting the following error messages in my php error log whenever the relevant theme template loads for a small minority of posts:
       WordPress database error Table 'mywpdatabasename.the' doesn't exist for query SHOW FULL COLUMNS FROM <code>the</code> made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/mytheme/single.php'), get_template_part, locate_template, load_template, require('/themes/mytheme/template-parts/the-part-containing-the-crp-call.php'), echo_crp, get_crp, get_crp_posts, CRP_Query->__construct, WP_Query->__construct, WP_Query->query, WP_Query->get_posts
       For the posts that trigger this error I get no CRP output – for example for this post https://londonkoreanlinks.net/book_item/north-korean-graphic-novels-seduction-of-the-innocent/ 
       But for the majority of posts there is absolutely no problem (and no error message generated). For example, the CRP output loads fine for this post https://londonkoreanlinks.net/book_item/critical-readings-on-christianity-in-korea-4-vol-set/ (You’ll see the CRP output at the very bottom of the page)
       I see that this or a similar problem seems to have occurred for other users (eg https://wordpress.org/support/topic/related-posts-not-displaying-sometimes-since-update/#post-14007839) but I’m struggling to understand why I’m only getting the problem for *some* posts but not the majority. Any ideas? For the specific problematic post mentioned above, the problem goes away with the “Limit content to be compared” parameter set at 98 or below, but comes back again with 99, 100 or 0. [When I uploaded this message, the limit was set at 99]
       Finding the posts impacted by this problem is like looking for a needle in a haystack so I’m not sure whether the 98/99 cut-off is typical. But my error log is dominated by errors of this nature.
       (I'm on v3.0.7 and WP5.8)
       Many thanks
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdatabase-error-querying-non-existent-table%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/#post-14698601)
 * [@goldeneagle](https://wordpress.org/support/users/goldeneagle/)
    Is it just 
   on this post?
 * And, can you confirm you’re running v3.0.7 of the plugin?
 *  Thread Starter [goldeneagle](https://wordpress.org/support/users/goldeneagle/)
 * (@goldeneagle)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/#post-14699030)
 * Hi there, yes, I’m using 3.0.7
 * At a rough count, around 10% of the most recent posts are impacted: for example:
 * [https://londonkoreanlinks.net/book_item/korean-minjung-theology-revisited/](https://londonkoreanlinks.net/book_item/korean-minjung-theology-revisited/)
   
   [https://londonkoreanlinks.net/book_item/tradition-treaties-and-trade/](https://londonkoreanlinks.net/book_item/tradition-treaties-and-trade/)
   [https://londonkoreanlinks.net/book_item/east-and-west-fusion-of-horizons/](https://londonkoreanlinks.net/book_item/east-and-west-fusion-of-horizons/)
 * Each seems to have a different cut-off for the point at which the related posts
   decide to display. If I shift the “Limit content to be compared” parameter to
   10, they all work; at 50 two of them work. It’s a mystery 😉 If I have to I’ll
   just set the parameter at somewhere below 50 and live with slightly less good
   results, because even the less good results are pretty good thanks to your hard
   work. But it would be nice to know what’s causing it. Same error message each
   time in the error log: a table called “the” is being queried.
 *  Thread Starter [goldeneagle](https://wordpress.org/support/users/goldeneagle/)
 * (@goldeneagle)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/#post-15033948)
 * Well, I’m still mystified by this. Following our email conversation I installed
   the debugging plugin you mentioned and experimented with adjusting the “Limit
   content to be compared” parameter for the impacted posts. I went cross-eyed trying
   to count the number of words which broke each post, before concluding there didn’t
   seem to be a common factor. What I did find, though, was that by doing a minor
   edit to the post (simply changing the spelling of a word didn’t work – I had 
   to add or delete a whole word at the *start* of the post) the problem went away.
   Why that should be the case I have no clue. It’s an endearing quirk which I can
   live with because I think the plugin is really good!
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/#post-15034272)
 * I think I spent about 2-3 days digging deep into the core of WP_Query. My analysis
   is a regex which finds the table name and it gets lost in some cases where. You
   have words. I narrowed it down to “from” but I think there might be others as
   well. I’m contemplating one change to run the content through a stopwords filter
   that WP_Query has before we do the matching.
 * That’s top priority and then I’ll put out a beta. Would you be in a position 
   to test that to see if this issue goes away?
 *  Thread Starter [goldeneagle](https://wordpress.org/support/users/goldeneagle/)
 * (@goldeneagle)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/#post-15039841)
 * Happy to help. I can’t guarantee super-fast turnaround, but happy to see if any
   fix works for my site as tbh this one’s baffling me 😉
    Not sure that “from” 
   is the culprit – I’ve got plenty of posts that work fine with that word within
   the word count limit – but I may not be understanding your post correctly. Anyway,
   feel free to email me if you want to get me to try out a fix. By the way, I’ve
   edited all the posts referred to above so that the problem has gone away. But
   there are plenty of others that I haven’t got around to fixing yet, for example
   [https://londonkoreanlinks.net/book_item/cultural-policy-in-south-korea/](https://londonkoreanlinks.net/book_item/cultural-policy-in-south-korea/)
   [https://londonkoreanlinks.net/book_item/the-personalist-ethic-and-the-rise-of-urban-korea/](https://londonkoreanlinks.net/book_item/the-personalist-ethic-and-the-rise-of-urban-korea/)
   [https://londonkoreanlinks.net/book_item/the-korean-womens-movement-and-the-state/](https://londonkoreanlinks.net/book_item/the-korean-womens-movement-and-the-state/)
 * (And profuse apologies for getting the name of the plugin wrong in the first 
   line of the original post at the top of this thread…)
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/#post-15041108)
 * [@goldeneagle](https://wordpress.org/support/users/goldeneagle/)
 * Please keep these ones with errors unfixed. I’m hoping what I implement gets 
   it fixed.
 * The “from” word is fixed as that is what I had narrowed it down to.
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/#post-15041115)
 * [@goldeneagle](https://wordpress.org/support/users/goldeneagle/)
 * Please keep these ones with errors unfixed. I’m hoping what I implement gets 
   it fixed.
 * The “from” word is fixed as that is what I had narrowed it down to.
 * By the way, the table name that gets referenced in the error, e.g. “the” in the
   above example – what is the word before and after the – this is either the first
   occurrence or the last occurrence within the word limit that you were playing
   with
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/#post-15064796)
 * [@goldeneagle](https://wordpress.org/support/users/goldeneagle/)
 * I’ve created a beta version which replaces all WP_Query stop words before the
   content is compared. I think that should hopefully work on this.
 * [https://github.com/WebberZone/contextual-related-posts/releases/tag/v3.1.0-beta1](https://github.com/WebberZone/contextual-related-posts/releases/tag/v3.1.0-beta1)
 * If you have a chance do give this a test. You an download the zip file and install
   it via Plugins > Add New
 *  Thread Starter [goldeneagle](https://wordpress.org/support/users/goldeneagle/)
 * (@goldeneagle)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/#post-15066625)
 * Thanks Ajay
    I installed the beta version on my staging site and that fixed the
   problem. No query error, and the requested number of related posts show nicely.
   No noticeable side effects! Looks like your forensic archaeological investigation
   of WP_Query’s innards has paid off!
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/#post-15066783)
 * Thank you for confirming! The new version includes additional features and I’m
   working on two major ones to bring to this version. It will likely see the light
   of day this side of Christmas if not sooner.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Database error: querying non-existent table’ is closed to new replies.

 * ![](https://ps.w.org/contextual-related-posts/assets/icon-256x256.png?rev=2985705)
 * [Contextual Related Posts](https://wordpress.org/plugins/contextual-related-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contextual-related-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contextual-related-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/contextual-related-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contextual-related-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contextual-related-posts/reviews/)

 * 10 replies
 * 2 participants
 * Last reply from: [Ajay](https://wordpress.org/support/users/ajay/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/database-error-querying-non-existent-table/#post-15066783)
 * Status: resolved