• Resolved mslade

    (@mslade)


    The documentation for parse_query indicates that it can accept a search_terms argument, an array of search terms. Passing this into get_posts() does not impact the results based on my tests.

    Looking at the code, it looks like search_terms is not actually used anywhere. get_posts may call parse_query if you also provide the s parameter (which seems pointless if you’re providing search_terms), and that may <i>set</i> search_terms, but I don’t see anywhere in query.php that it’s actually used.

    Can anyone enlighten me?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Where are you seeing search_terms used in documentation? ‘search_terms’ is an array key used internally by WP_Query::parse_search(). It’s not an acceptable query var anywhere, we must use only the ‘s’ query var.

    While $q['search_terms'] is an array, the ‘s’ query var only accepts strings. It’s the job of WP_Query::parse_search() to break that string down into array components. That array is used to construct a SQL fragment that’s eventually used to query for posts containing the provided search strings.

    Thread Starter mslade

    (@mslade)

    Hi bcworkz, thanks for your response.

    search_terms is referenced in the documentation parse_query():

    * @type array $search_terms Array of search terms.

    …which the doc block for get_posts says to refer to for a full list of available arguments.

    From your explanation and from reading the code, I think the doc block is incorrect and search_terms is ignored as an argument to parse_query or get_posts.

    Moderator bcworkz

    (@bcworkz)

    I’d say it’s incorrect too. In fact, at least in 4.4.1 the string “$search_terms” no longer appears in the WP distribution anywhere. I didn’t see it in WP_Query::parse_query() so I resorted to grep, which turned up nothing. Apparently others have agreed with us ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How does parse_query()'s search_terms parameter work, if at all?’ is closed to new replies.