你的问题更多的是关于SQL而不是WordPress。
如果要将术语名称按数字排序,通常可以尝试
SELECT * FROM wp_terms ORDER BY name+0 ASC
或
SELECT * FROM wp_terms ORDER BY name*1 ASC
或使用CAST:
SELECT * FROM wp_terms ORDER BY CAST(name AS SIGNED) ASC
您可以使用的位置
SIGNED
,
UNSIGNED
或者也许
DECIMAL(10,2)
, 取决于你的数字。
更新以测试排序,然后可以访问您的PHPMyAdmin并运行此查询:
SELECT tool_terms.name AS tname, tool_posts.* FROM tool_posts
LEFT OUTER JOIN tool_term_relationships ON tool_posts.ID=tool_term_relationships.object_id
LEFT OUTER JOIN tool_term_taxonomy USING (term_taxonomy_id)
LEFT OUTER JOIN tool_terms USING (term_id)
WHERE 1=1
AND tool_posts.post_type = \'landschapselement\'
AND (tool_posts.post_status = \'publish\' OR tool_posts.post_status = \'draft\' OR tool_posts.post_status = \'pending\' OR tool_posts.post_status = \'private\')
AND (taxonomy = \'beheerseenheidnummer\' OR taxonomy IS NULL)
GROUP BY object_id
ORDER BY tool_terms.name+0 ASC, tool_posts.post_title ASC
看看我换的地方是否有用
ORDER BY GROUP_CONCAT(tool_terms.name ORDER BY name ASC) ASC
与
ORDER BY tool_terms.name+0 ASC, tool_posts.post_title ASC
其中,我们按照分类法数值对文章进行排序,然后第二个顺序是在文章标题上。我还添加了字段
tool_terms.name AS tname
到
SELECT
部分这适用于我的安装。
您也可以尝试替换
$clauses[\'orderby\'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
$clauses[\'orderby\'] .= ( \'DESC\' == strtoupper( $wp_query->get(\'order\') ) ) ? \'ASC\' : \'DESC\';
使用:
$clauses[\'orderby\'] = " {$wpdb->terms}.name+0 ";
$clauses[\'orderby\'] .= ( \'DESC\' == strtoupper( $wp_query->get(\'order\') ) ) ? \'ASC\' : \'DESC\';
$clauses[\'orderby\'] = ", {$wpdb->posts}.post_title ASC ";