基于多个搜索,这是我试图按两个不同的元键值排序的代码。
\'meta_query\' => array(
\'relation\' => \'AND\',
\'listing_order\' => array(
\'key\' => \'atsc_bod_listing_order\',
\'compare\' => \'EXISTS\',
),
\'last_name\' => array(
\'key\' => \'atsc_bod_last_name\',
\'compare\' => \'EXISTS\',
),
),
\'orderby\' => array(
\'listing_order\' => \'ASC\',
\'last_name\' => \'ASC\',
),
我想先按数值排序,如果数值相同,则按姓氏排序。此代码不返回任何结果。我认为这与不知道排序字段是“meta\\u value\\u num”还是“meta\\u value”有关,但我不确定如何/在何处添加该信息。
下面是包含以下建议的完整代码。
<?php
$args = array (
\'post_type\' => \'atsc_bod\',
\'posts_per_page\' => -1,
\'post_status\' => \'publish\',
\'meta_query\' => array(
\'relation\' => \'AND\',
\'listing_order\' => array(
\'key\' => \'atsc_bod_listing_order\',
\'compare\' => \'EXISTS\',
\'type\' => \'NUMERIC\',
),
\'last_name\' => array(
\'key\' => \'atsc_bod_last_name\',
\'compare\' => \'EXISTS\',
),
),
\'orderby\' => array(
\'listing_order\' => \'ASC\',
\'last_name\' => \'ASC\',
),
);
$loop = new WP_Query($args);
?>