Title: Bug in sql function in YARPP_Cache
Last modified: August 20, 2016

---

# Bug in sql function in YARPP_Cache

 *  Resolved [Daniel Dvorkin](https://wordpress.org/support/users/mzaweb/)
 * (@mzaweb)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/)
 * Around line 171 of class-cache.php you’re doing:
 * `foreach ( (array)$weight['tax'] as $tax => $weight )`
 * Setting the inner value of that foreach to $weight destroys the original $weight,
   so a few lines below when you do:
 * `if ( count($exclude_tt_ids) || count((array) $weight['tax']) || count($require_tax))`
 * $weight[‘tax’] is invalid, throws a notice, and it’s always 0.
 * [http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/](http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/)

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

 *  [mitcho (Michael Yoshitaka Erlewine)](https://wordpress.org/support/users/mitchoyoshitaka/)
 * (@mitchoyoshitaka)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/#post-3241479)
 * Oh my god. Thank you for bringing this to my attention… this is terribly embarrassing,
   and I guess we’ve all been very lucky that YARPP has continued to function in
   the mean time.
 * My understanding of the effect is that `count((array) $weight['tax'])` was interpreted
   as `count(array(0))`, and thus the term_relationships were being joined even 
   when not necessary. Is that right? How did you find this?
 * Will fix in a quick bugfix release.
 *  [mitcho (Michael Yoshitaka Erlewine)](https://wordpress.org/support/users/mitchoyoshitaka/)
 * (@mitchoyoshitaka)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/#post-3241521)
 * 4.0.1 beta 2:
 * [http://downloads.wordpress.org/plugin/yet-another-related-posts-plugin.4.0.1b2.zip](http://downloads.wordpress.org/plugin/yet-another-related-posts-plugin.4.0.1b2.zip)
 * Please let me know what you think. Thanks again!
 *  Thread Starter [Daniel Dvorkin](https://wordpress.org/support/users/mzaweb/)
 * (@mzaweb)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/#post-3241536)
 * No, the other way around. It wasn’t adding the joins, so the query was failing.
   In fact, it wasn’t working at all for me when using the YARPP_Cache_Bypass (using
   yarpp_get_related manually). It was working on table cache, though, when using
   the auto add.
 * Didn’t test it, but [http://plugins.svn.wordpress.org/yet-another-related-posts-plugin/tags/4.0.1b2/class-cache.php](http://plugins.svn.wordpress.org/yet-another-related-posts-plugin/tags/4.0.1b2/class-cache.php)
   looks good.
 *  Thread Starter [Daniel Dvorkin](https://wordpress.org/support/users/mzaweb/)
 * (@mzaweb)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/#post-3241537)
 * So, you’re right about count(array(0)), but that’s 0, so it was not entering 
   the IF.
 *  [mitcho (Michael Yoshitaka Erlewine)](https://wordpress.org/support/users/mitchoyoshitaka/)
 * (@mitchoyoshitaka)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/#post-3241544)
 * count(array(0)) is 1 🙂 so it was entering.
 *  Thread Starter [Daniel Dvorkin](https://wordpress.org/support/users/mzaweb/)
 * (@mzaweb)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/#post-3241547)
 *     ```
       php -r 'var_dump(count($arr["bad_index"]));'
       title:7: bad math expression: operand expected at
       ```
   
 * “bad_index…’
    1;phpPHP Notice: Undefined variable: arr in Command line code on
   line 1 PHP Stack trace: PHP 1. {main}() Command line code:0
 * Notice: Undefined variable: arr in Command line code on line 1
 * Call Stack:
    0.0001 626184 1. {main}() Command line code:0
 * int(0)
    `
 * it was not 🙂
 *  Thread Starter [Daniel Dvorkin](https://wordpress.org/support/users/mzaweb/)
 * (@mzaweb)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/#post-3241548)
 * Hate the formatting for code. Let’s try again:
 * > php -r ‘var_dump(count($arr[“bad_index”]));’
   >  title:7: bad math expression:
   > operand expected at `”bad_index…’ 1;phpPHP Notice: Undefined variable: arr 
   > in Command line code on line 1 PHP Stack trace: PHP 1. {main}() Command line
   > code:0
   > Notice: Undefined variable: arr in Command line code on line 1
   > Call Stack:
   >  0.0001 626184 1. {main}() Command line code:0
   > int(0)
 *  [mitcho (Michael Yoshitaka Erlewine)](https://wordpress.org/support/users/mitchoyoshitaka/)
 * (@mitchoyoshitaka)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/#post-3241553)
 * well, $arr was defined, so I think it’s 1… but either way, can you confirm that
   this is fixed for 4.0.1?
 *  Thread Starter [Daniel Dvorkin](https://wordpress.org/support/users/mzaweb/)
 * (@mzaweb)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/#post-3241554)
 * Yup, working.
 * It’s weird, because I found the issue thanks to an error on my mysql log because
   of the missing join. Anyway, it’s fixed.
 * Thanks!
 *  [mitcho (Michael Yoshitaka Erlewine)](https://wordpress.org/support/users/mitchoyoshitaka/)
 * (@mitchoyoshitaka)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/#post-3241557)
 * Great! Hoping to push this release tomorrow… want to let it bake a bit. If you
   want, the latest beta is b3:
 * [http://downloads.wordpress.org/plugin/yet-another-related-posts-plugin.4.0.1b3.zip](http://downloads.wordpress.org/plugin/yet-another-related-posts-plugin.4.0.1b3.zip)

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

The topic ‘Bug in sql function in YARPP_Cache’ is closed to new replies.

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

 * 10 replies
 * 2 participants
 * Last reply from: [mitcho (Michael Yoshitaka Erlewine)](https://wordpress.org/support/users/mitchoyoshitaka/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/bug-in-sql-function-in-yarpp_cache/#post-3241557)
 * Status: resolved