8

I have a simple question, but can't find the answer anywhere. What exactly does the 's' parameter search when used in a query? Ex:

$args = array( 's' => $keyword ); $query = new WP_Query($args);

Does it just search post content, or does it also look at title, tags, etc?

EDIT: Just to clarify. The question is what post fields are being searched, not what data is being returned.

1
  • The default fields being searched are post content and post title. Commented May 26, 2015 at 19:36

1 Answer 1

17

As usual it's most reliable to dump the resulting SQL query and see:

SELECT wp_posts.ID
FROM wp_posts
WHERE 1=1
  AND (((wp_posts.post_title LIKE '%keyword%')
        OR (wp_posts.post_content LIKE '%keyword%')))
  AND wp_posts.post_type = 'post'
  AND ((wp_posts.post_status = 'publish'))
ORDER BY wp_posts.post_date DESC LIMIT 0,5

The only two things native search is considering are title and content.

2
  • 1
    Great, thanks for the help! I didn't realize that you could dump the query itself but I'll check that out Commented May 27, 2015 at 2:29
  • 4
    $wpdb->last_query :)
    – Rarst
    Commented May 27, 2015 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.