我有全名作为标题,想按姓氏排序。
我怎样才能用wordpress做到这一点?
在PHP中,它将遵循-
SELECT * from posts ORDER BY SUBSTR(LTRIM(post_title), LOCATE(\' \',LTRIM(post_title)))
当前获取人员类别的代码为;
$args = array(
\'posts_per_page\'=>50,
\'cat\'=> \'39,-41\',
\'orderby\'=>\'title\',
\'order\'=>\'ASC\',
);
query_posts($args);
我怎样才能得到第二个词序?
最好的,丹。
SO网友:goldenapples
有一个过滤器“posts\\u orderby”,允许您指定自己的ORDER BY子句。在您的情况下,代码如下所示:
add_filter( \'posts_orderby\', \'order_by_surname\' );
function order_by_surname( $orderby, $query ) {
// first you should check to make sure sure you\'re only filtering the particular query
// you want to hack. return $orderby if its not the correct query;
return "ORDER BY SUBSTR(
LTRIM({$wpdb->posts}.post_title),
LOCATE(\' \',LTRIM({$wpdb->posts}.post_title)))";
}