我尽我所能尝试在WordPress函数中排序,但无法得到我想要的。我最终听从了PieterGoosen的建议,做了一个usort()。以下是我现在拥有的:
WP\\U查询$参数
$args = array (
\'post_type\' => array( \'member\' ),
\'tax_query\' => array(
array(
\'taxonomy\' => \'group\',
\'field\' => \'slug\',
\'terms\' => \'town-board\'
),
),
);
自定义排序功能
function custom_sort($a, $b) {
if ( get_post_meta($a->ID, \'_town-board_position\', true) === \'Town Chairman\' ) {
return -1;
} else if ( strpos( get_post_meta($a->ID, \'_town-board_position\', true), \'Supervisor\' ) !== false and strpos( get_post_meta($b->ID, \'_town-board_position\', true), \'Supervisor\' ) !== false ) {
return strcmp(get_post_meta($a->ID, \'_town-board_position\', true), get_post_meta($b->ID, \'_town-board_position\', true));
} else {
return 1;
}
}
现在,它按我想要的排序:镇主席>主管1>2>3>4
谢谢大家的建议。