Answer the question
In order to leave comments, you need to log in
Query from the database, one field - many values?
Actually in WordPress, data is stored in add. fields such as meta_key='type'
, meta_value='buy'
, meta_key='price'
, meta_value='10000'
etc. task is to make a selection. there are a lot of these metafields, WP tools can be attached to the search_meta_join
type:
$join .= " JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id ";
search_meta_where
, and here I don’t know how to do it right, I get such a requestSELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id WHERE 1=1 AND wp_posts.post_type IN ('post', 'page', 'attachment') AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 1 AND wp_posts.post_status = 'private') AND ( wp_postmeta.meta_value IN ('rent','flat')) GROUP BY wp_posts.ID HAVING COUNT(*) = 2
Answer the question
In order to leave comments, you need to log in
Colleague, you are using WordPress and metafields for this in vain - there are fields of the varchar type and without indexes. After a while, it will start to slow down terribly for you. Design your structure the right way - with primary keys like int and so on.
It seems he figured it out himself, for each key-value you will need to make a new JOIN of type
JOIN wp_postmeta as wp_postmeta_1 ON wp_posts.ID = wp_postmeta_1.post_id
AND wp_postmeta_1.meta_value > 8000
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question