php – WordPress WP_Query where子句与OR?

前端之家收集整理的这篇文章主要介绍了php – WordPress WP_Query where子句与OR?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
你好朋友这是我的WP_Query的args.
$args = array('post_type' => 'job_listing');
$args['Meta_query']=array(
   'relation' => 'OR',array(
        'key' => 'app_trailer-type','value' => $job_tailor,'compare' => 'LIKE'
    ),array(
        'key' => 'app_pay-type','value' => $app_pay_type,array(
        'key' => 'geo_address','value' => $geo_address,array(
        'key' => 'geo_country','value' => $geo_country,array(
        'key' => 'geo_short_address','value' => $geo_short_address,);

这是返回查询之类的.

SELECT sql_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  INNER JOIN wp_postMeta ON (wp_posts.ID = wp_postMeta.post_id)
INNER JOIN wp_postMeta AS mt1 ON (wp_posts.ID = mt1.post_id)
INNER JOIN wp_postMeta AS mt2 ON (wp_posts.ID = mt2.post_id)
INNER JOIN wp_postMeta AS mt3 ON (wp_posts.ID = mt3.post_id)
INNER JOIN wp_postMeta AS mt4 ON (wp_posts.ID = mt4.post_id) WHERE 1=1  AND wp_posts.post_type = 'job_listing' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'expired' OR wp_posts.post_status = 'tr_pending' OR wp_posts.post_status = 'tr_Failed' OR wp_posts.post_status = 'tr_completed' OR wp_posts.post_status = 'tr_activated' OR wp_posts.post_status = 'private') AND ( (wp_postMeta.Meta_key = 'app_trailer-type' AND CAST(wp_postMeta.Meta_value AS CHAR) LIKE '%Flatbed%')
AND  (mt1.Meta_key = 'app_pay-type' AND CAST(mt1.Meta_value AS CHAR) LIKE '%Per Week%')
AND  (mt2.Meta_key = 'geo_address' AND CAST(mt2.Meta_value AS CHAR) LIKE '%Davenport%')
AND  (mt3.Meta_key = 'geo_country' AND CAST(mt3.Meta_value AS CHAR) LIKE '%United States%')
AND  (mt4.Meta_key = 'geo_short_address' AND CAST(mt4.Meta_value AS CHAR) LIKE '%Davenport%') ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0,10

我需要查询查询.

SELECT sql_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  INNER JOIN wp_postMeta ON (wp_posts.ID = wp_postMeta.post_id)
INNER JOIN wp_postMeta AS mt1 ON (wp_posts.ID = mt1.post_id)
INNER JOIN wp_postMeta AS mt2 ON (wp_posts.ID = mt2.post_id)
INNER JOIN wp_postMeta AS mt3 ON (wp_posts.ID = mt3.post_id)
INNER JOIN wp_postMeta AS mt4 ON (wp_posts.ID = mt4.post_id) WHERE 1=1  AND wp_posts.post_type = 'job_listing' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'expired' OR wp_posts.post_status = 'tr_pending' OR wp_posts.post_status = 'tr_Failed' OR wp_posts.post_status = 'tr_completed' OR wp_posts.post_status = 'tr_activated' OR wp_posts.post_status = 'private') AND ( (wp_postMeta.Meta_key = 'app_trailer-type' OR CAST(wp_postMeta.Meta_value AS CHAR) LIKE '%Flatbed%')
OR  (mt1.Meta_key = 'app_pay-type' AND CAST(mt1.Meta_value AS CHAR) LIKE '%Per Week%')
OR  (mt2.Meta_key = 'geo_address' AND CAST(mt2.Meta_value AS CHAR) LIKE '%Davenport%')
OR  (mt3.Meta_key = 'geo_country' AND CAST(mt3.Meta_value AS CHAR) LIKE '%United States%')
OR  (mt4.Meta_key = 'geo_short_address' AND CAST(mt4.Meta_value AS CHAR) LIKE '%Davenport%') ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0,10

请帮忙.

改变args与喜欢.
$args = array('post_type' => 'job_listing','relation' => 'OR');
$args['Meta_query']=array(
    array(
        'key' => 'app_trailer-type',);
原文链接:https://www.f2er.com/php/139169.html

猜你在找的PHP相关文章