WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
Error: Warning: mysql_real_escape_string() expects parameter (10 posts)

  1. mamouneyya
    Member
    Posted 3 years ago #

    When I try to search for something, I get this error on the top of the page with no search results (even if the string I am searching for exists):

    Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /home/****/public_html/wp-content/plugins/relevanssi/relevanssi.php on line 732

  2. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    That should be a string... I'll have to investigate this.

  3. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    What kind of post type settings you're using? (Because this has to do with post types.)

  4. mamouneyya
    Member
    Posted 3 years ago #

  5. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    Sorry, but I don't get how an array could get there.

    Here's a way we can debug this further. Find the line

    $post_type = mysql_real_escape_string($post_type);

    change it to this:

    var_dump($post_type);
    		$post_type = mysql_real_escape_string($post_type);

    and then let me know what comes out.

  6. mamouneyya
    Member
    Posted 3 years ago #

    array(2) { [0]=> string(7) "schools" [1]=> string(4) "news" }

    It seems that the custom post types I have, which are 'schools' and 'news', are being passed as an array.

  7. mamouneyya
    Member
    Posted 3 years ago #

    Correction: ... are being stored as an array, I meant.

    Hmm, I've just tried to add the following two lines right after line#464:

    462	$post_type = false;
    463	if (isset($query->query_vars["post_type"]) && $query->query_vars["post_type"] != 'any') {
    464		$post_type = $query->query_vars["post_type"];
    
    465		if(is_array($post_type))
    466			$post_type = implode(",", $post_type);
    
    467	}

    Now the warning doesn't show up anymore. However, still no search results!

  8. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    I've got some ideas what may be causing this. I'll have to experiment with custom post types, I don't think I have any set up in my test blog right now.

    Just one more question now: do you want to restrict the search to those custom types or not? I'm just wondering where they come from. Does your search form add them?

  9. mamouneyya
    Member
    Posted 3 years ago #

    Actually, I do want to restrict the search to 'Pages', 'Schools', and 'News' post types. But to answer your question: No. I am using WP default search form 'get_search_form()'.

    If that helps, I can give you back-end access to the site.

  10. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    I still don't get where those post_types appear. I added some custom post types to my test blog and still, when I search, I get the correct "any" post_type in query_vars.

    Actually, I can't even make WordPress have an array in the post_type if I try. I suppose it is technically possible (there's some reference to it in the source code), but I don't know how that would happen.

    So, it looks like I just have to say I'm sorry, but I don't have a clue what's causing this.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags