我无法弄清楚我的查询有什么问题。我有三个控制帖子顺序的元素:quartier
,block
和number
。它运作良好。
我想添加一个名为street
的第四个。当我这样做时,什么也没有。我想也许street
存在问题,但是如果我离开street
但是删除了block
,它会再次运行并适当地使用street
。
我的结论是数据库每次查询只接受有限数量的选择器。真的吗?或者我错过了什么?
$query = "SELECT `wp_posts`.`post_title` , `wp_posts`.`ID` , `end`.`meta_value` AS `enddate` , `start`.`meta_value` as `startdate`, `quartier`.`meta_value` AS `thequartier`, `street`.`meta_value` AS `thestreet`, `number`.`meta_value` AS `thenumber`, `block`.`meta_value` AS `theblock`
FROM `wp_posts` , `wp_postmeta` AS `end` , `wp_postmeta` AS `start` , `wp_postmeta` AS `quartier`, `wp_postmeta` AS `street`, `wp_postmeta` AS `number`, `wp_postmeta` AS `block`
WHERE `wp_posts`.`post_type` = 'listing'
AND `wp_posts`.`ID` = `end`.`post_id`
AND `wp_posts`.`ID` = `start`.`post_id`
AND `wp_posts`.`ID` = `quartier`.`post_id`
AND `wp_posts`.`ID` = `street`.`post_id`
AND `wp_posts`.`ID` = `block`.`post_id`
AND `wp_posts`.`ID` = `number`.`post_id`
AND `end`.`meta_key` = 'theend'
AND `end`.`meta_value` >= '".time()."'
AND `start`.`meta_key` = 'thestart'
AND `start`.`meta_value` <= '".time()."'
AND `quartier`.`meta_key` = 'quartier'
AND `street`.`meta_key` = 'street'
AND `number`.`meta_key` = 'number'
AND `block`.`meta_key` = 'block'
AND `wp_posts`.`post_status` = 'publish'
GROUP BY `wp_posts`.`ID`
ORDER BY `thequartier` + 0 ASC";
$calendar = $wpdb->get_results($query, ARRAY_A);
foreach ($calendar as $key => $row) {
$thequartier[$key] = $row['thequartier'];
$thestreet[$key] = $row['thestreet'];
$theblock[$key] = $row['theblock'];
$thenumber[$key] = $row['thenumber'];
}
// Sort the data with volume descending, edition ascending
array_multisort($thequartier, SORT_ASC, $theblock, SORT_ASC, $thestreet, SORT_ASC, $thenumber, SORT_ASC, $calendar);
更新:我找到了我的问题的解决方案,添加以下行以允许过多的选择器:
$wpdb->query("SET SQL_BIG_SELECTS=1");