WP Custom Query for meta search

Standard
SELECT * FROM wp_posts p, wp_postmeta m, wp_terms t, wp_term_relationships r, wp_term_taxonomy tt 
WHERE p.post_type='your-post-type' 
AND p.ID=m.post_id 
AND p.id=r.object_id 
AND r.term_taxonomy_id=tt.term_taxonomy_id 
AND tt.term_id = t.term_id 
AND ( t.name LIKE '%90036%' OR p.post_title LIKE '%90036%' 
OR ( (meta_key='Address 1' AND meta_value LIKE '%90036%') 
OR (meta_key ='Address 2' AND meta_value LIKE '%90036%') 
OR (meta_key='State' AND meta_value LIKE '%90036%') 
OR (meta_key='City' AND meta_value LIKE '%90036%') 
OR (meta_key='Zip' AND meta_value LIKE '%90036%') ) ) 
GROUP BY ID 
ORDER BY post_title
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: