Wordpress get_pages按包含非拉丁字符的post_title排序


Wordpress get_pages sort by post_title containing non-latin characters

我使用下面的代码输出按页面标题排序的Wordpress页面。

$args = array(
    'sort_order' => 'asc',
    'sort_column' => 'post_title',
    'hierarchical' => 1,
    'child_of' => $page,
    'parent' => -1,
    'post_type' => 'page',
    'post_status' => 'publish'
);
$pages = get_pages($args);

除了以非拉丁字符开头的页面外,它可以正常工作。Å被排序为A,它应该在最后,按照我们的瑞典字母。

你可以试试这个

$args = array(
   'orderby' => 'post_title',
   'order' => 'asc',
   'hierarchical' => 1,
   'child_of' => $page,
   'parent' => -1,
   'post_type' => 'page',
   'post_status' => 'publish'
);
$pages = get_pages($args);

似乎常规的utf8_general_ci不能解决瑞典字母的这个问题。这个SQL命令解决了问题。

alter table wp_posts convert to character set utf8 collate utf8_swedish_ci;

有一个很棒的插件叫做转换WP数据库到UTF-8。我一直在用它。这个插件添加了一个名为"UTF-8 DB转换器"的子菜单页面到插件菜单。只需点击"开始转换",插件将自动执行所需的SQL查询,以改变所有现有WordPress表的字符集和排序。

你只需要做一次每个网站,问题是固定的好。然后你可以卸载这个插件。

虽然这个插件对我来说一直运行得很顺利,但在尝试这个过程之前,正确的做法是备份你的WordPress数据库。