Error when searching for an empty string

  • Hey RM Team,

    when I am searching for an empty string RankMath shows the following error Message:

    Uncaught Error: Call to undefined method RankMath\Paper\Search::set_object() in /var/www/html/wp-content/plugins/seo-by-rank-math/includes/frontend/paper/class-paper.php on line 109Uncaught Error: Call to undefined method RankMath\Paper\Search::set_object() in /var/www/html/wp-content/plugins/seo-by-rank-math/includes/frontend/paper/class-paper.php on line 109

    It seems like the search string can’t be empty with RankMath installed.

    To get around this i’ll halt the query when ?s= is empty but this should be fixed.

    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    I have raised this issue with our dev team and we will be addressing this soon.

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Hello,

    I don’t get any error on my setup when search string is empty. Here is a screencast: https://i.rankmath.com/SoP9RP
    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WP logins in the designated Sensitive Data section.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    Temporary Login Without Password

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    WP Security Audit Log

    We really look forward to helping you.

    I see. Tried it on two installations to proof it has something to do with RankMath itself.. (I suppose I had to do some more tests)

    It looks like the error is triggered when the Polylang Extension is installed on the page. (Both installations where running on polylang…)

    Both deactivating Polylang OR RankMath removes the error. There must be some incompability. I’ll also try to reach out to the Polylang Team.

    A conditional check for is_search on line 106 at class-paper.php helps:
    } elseif ( Post::is_simple_page() && !is_search() ) {

    It looks like Post::is_simple_page() returns true on an empty search when Polylang is active

    I encountered the error only appears if a Posts Page is specified under Settings -> Reading.

    The Polylang Team is also involved and they’re looking on their side. I’ll give you updates as soon as I have more information.

    Hi Bastian,

    I see.

    Please let me know what the Polylang team says so we can perform further diagnostics.

    As soon as they respond to my last email I will let you know.

    I’m still texting with Polylang atm.
    It looks like I found the malefactor.

    Polylang sets the following query vars when searching for an empty string while a language is selected:

    WP_Query->is_home is set to true
    WP_Query->is_archive is set to false
    WP_Query->is_tax is set to false

    I’m waiting for a response from Polylang if i’m right but for me it looks like this might trigger the error.

    Edit: Yep I am right with my assumption. Still waiting for Polylang but i tried commenting out this section and the error has been gone.

    I think a conditional check if we’re on a search page in the get_simple_page_id() method that returns false might do the trick here.

    
    	/**
    	 * Get the ID of the current page.
    	 *
    	 * @return int The ID of the page.
    	 */
    	public static function get_simple_page_id() {
    		/**
    		 * Filter: Allow changing the default page ID. Short-circuit if 3rd party set page ID.
    		 *
    		 * @param unsigned int $page_id The default page id.
    		 */
    		$page_id = apply_filters( 'rank_math/pre_simple_page_id', false );
        
        if ( \is_search() && get_query_var( 's' ) == '' {
          return false;
        }
        
    		if ( false !== $page_id ) {
    			return $page_id;
    		}
    
    		if ( \is_singular() ) {
    			return get_the_ID();
    		}
    
    		if ( self::is_posts_page() ) {
    			return get_option( 'page_for_posts' );
    		}
    
    		if ( self::is_shop_page() ) {
    			return self::get_shop_page_id();
    		}
    
    		/**
    		 * Filter: Allow changing the default page ID.
    		 *
    		 * @param unsigned int $page_id The default page ID.
    		 */
    		return apply_filters( 'rank_math/simple_page_id', 0 );
    	}
    

    Another one:
    This is the solution Polylang came up for me.

    <?php
    /**
     * Plugin Name: Polylang & Rank Math SEO Compatibility
     * Author: WP Syntex
     * Author URI: https://polylang.pro/
     * Description: Provides compatibility between Polylang / Polylang Pro and SEO by RankMath
     * Version: 0.1.0
     */
    
    add_filter( 'rank_math/pre_simple_page_id', 'on_empty_search_query' );
    
    /**
     * Prevent RankMath from setting a Post object on an empty search query
     *
     * @see rank_math/pre_simple_page_id
     *
     * @return int|bool 0 if is an empty search query, false otherwise
     */
    function on_empty_search_query() {
    	if ( is_search() && get_query_var( 's' ) === '' ) {
    		return 0;
    	} else {
    		return false;
    	}
    }

    Hi Bastian,

    Thanks for sharing these findings.

    I am super happy that this is now resolved, I will pass this on to our developers.

    Thank you.

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

The ticket ‘Error when searching for an empty string’ is closed to new replies.