你的头衔不是数字。如果没有数字,就无法进行数字排序。“T”在数字序列中的位置?
但是,如果您有一个一致的模式,可以利用它来拆分标题--我使用了一个空格字符,并假设了一个类似“title”+空格+“number”的模式--您可以这样做:
function numeric_sort_title_field($fields) {
remove_filter(\'posts_fields\',\'numeric_sort_title_field\');
global $wpdb;
$fields .= \', \';
$fields .= \'REVERSE(\';
$fields .= \'LEFT(\';
$fields .= "REVERSE({$wpdb->posts}.post_title),";
$fields .= "LOCATE(\' \',REVERSE({$wpdb->posts}.post_title))";
$fields .= \')\';
$fields .= \') + 0\';
$fields .= \' AS number\';
$fields .= \', \';
$fields .= \'REVERSE(\';
$fields .= \'LEFT(\';
$fields .= "REVERSE({$wpdb->posts}.post_title),";
$fields .= "LENGTH({$wpdb->posts}.post_title) - LOCATE(\' \',REVERSE({$wpdb->posts}.post_title))";
$fields .= \')\';
$fields .= \') + 0\';
$fields .= \' AS title_text\';
return $fields;
}
add_filter(\'posts_fields\',\'numeric_sort_title_field\');
function numeric_sort_title($orderby) {
remove_filter(\'posts_orderby\',\'numeric_sort_title\');
$orderby = \' title_text, number\';
return $orderby;
}
add_filter(\'posts_orderby\',\'numeric_sort_title\');
$q = new WP_Query(
array(
\'post_type\' => \'post\',
\'posts_per_page\' => -1
)
);
var_dump($q->request);
if ($q->have_posts()) {
while ($q->have_posts()) {
$q->the_post();
the_title();
echo \'<br>\';
}
}
您应该按照标题的文本部分和数字部分对帖子进行排序。