Skip to content

Instantly share code, notes, and snippets.

@dingo-d
Created December 6, 2017 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dingo-d/95cb64baa001afffbdead5e1b02f3d7a to your computer and use it in GitHub Desktop.
Save dingo-d/95cb64baa001afffbdead5e1b02f3d7a to your computer and use it in GitHub Desktop.
Modification of the search query in WordPress
SELECT rezultat, ord
FROM (
SELECT wp_posts.post_title rezultat, 1 ord, wp_posts.ID ID, wp_posts.post_type type, wp_posts.post_status status FROM wp_posts WHERE wp_posts.post_title LIKE '%search query%'
UNION
SELECT wp_posts.post_content rezultat, 2 ord, wp_posts.ID ID, wp_posts.post_type type, wp_posts.post_status status FROM wp_posts WHERE wp_posts.post_content LIKE '%search query%'
UNION
SELECT wp_postmeta.meta_value rezultat, 3 ord, wp_postmeta.post_id ID, 1 type, 1 status FROM wp_postmeta WHERE wp_postmeta.meta_value LIKE '%search query%'
) rez
WHERE 1=1
AND (rez.type = 'post' OR rez.type = 'page' OR rez.type = 'faq-type')
AND rez.type != 'wpcf7_contact_form'
AND rez.type != 'revision'
AND rez.status = 'publish'
ORDER BY ord ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment