• Resolved mcondave

    (@mcondave)


    I recently updated WordPress and all of the plugins on our site including WPML and Relevanssi. After doing so, a coworker found out that searching for the acronym “TROOP” caused the results page to break. It may be relevant that we get zero results searching for “TROOP.” I did some digging and found out that there was an error. Here’s the stack trace for it:

    PHP Fatal error:  Uncaught Error: Cannot use object of type WP_Error as array in /var/www/vhosts/our-site/wp-content/plugins/relevanssi/lib/utils.php:417
    Stack trace:
    #0 /var/www/vhosts/our-site/wp-content/plugins/relevanssi/lib/stopwords.php(95): relevanssi_get_current_language()
    #1 /var/www/vhosts/our-site/wp-content/plugins/relevanssi/lib/common.php(594): relevanssi_fetch_stopwords()
    #2 /var/www/vhosts/our-site/wp-content/plugins/relevanssi/lib/didyoumean.php(159): relevanssi_tokenize()
    #3 /var/www/vhosts/our-site/wp-content/plugins/relevanssi/lib/didyoumean.php(68): relevanssi_simple_generate_suggestion()
    #4 /var/www/vhosts/our-site/wp-content/plugins/relevanssi/lib/didyoumean.php(31): relevanssi_simple_didyoumean()
    #5 /var/www/vhosts/our-site/wp-content/themes/our-theme/search.php(221): relevanssi_didyoumean()
    #6 /var/www/vhosts/our-site/wp-includes/template-loader.php(106): include('/var/www/vhosts...')
    #7 /var/www/vhosts/our-site/wp-blog-header.php(19): require_once('/var/www/vhosts...')
    #8 /var/www/vhosts/our-site/index.php(17): require('/var/www/vhosts...')
    #9 {main}
      thrown in /var/www/vhosts/our-site/wp-content/plugins/relevanssi/lib/utils.php on line 417

    The error seemed to happen with any phrase that contained “oop” at the end of it (loop, goop, boop, etc.) except for another acronym on our site, “MOOP.” I eventually determined that disabling WPML allowed us to search those specific terms without error. The “Limit results to current language” WPML searching setting did not solve the problem.

    With WPML enabled, I was able to avoid the error by commenting out the block which started on search.php(221) from the stack trace. It was the entire section that runs the relevanssi_didyoumean function.

    <?php if (function_exists('relevanssi_didyoumean')) { relevanssi_didyoumean(get_search_query(), "<p>Did you mean: ", "?</p>", 5); } ?>
    
    <?php if( have_posts() ) :  ?>
        <div class="search-count">
        <p><?php echo sprintf( __( 'Results %s - %s of %s', 'medicareinteractive' ), $range_start, $range_end, $search_count ); ?></p>
        </div>
    <?php endif; ?>

    This has been within our template since we installed Relevanssi. We don’t have search logging enabled and, it’s my understanding that this is required for the did you mean function to work with the free version of Relevanssi.

    Is this problem reproduceable or is there anything from recent updates that may have caused the did you mean function to error out like that?

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Hmm, yeah, that’s a silly coding error on my part. I’m aware that WPML may sometimes return a WP_Error instead of proper language information and am checking for that, but then the code forgets about that and still tries to access the language information, leading to what you’re seeing here.

    You can try replacing the lib/utils.php in Relevanssi with this file: https://github.com/msaari/relevanssi/blob/master/lib/utils.php

    That should help with the problem here.

    Thread Starter mcondave

    (@mcondave)

    Yup, that did the trick. Thank you! I’ll mark the thread resolved.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WPML + “Did you mean” function error’ is closed to new replies.