最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filters - Custom sort orderby question

programmeradmin0浏览0评论

I needed to sort a custom post type by the last word (i.e. last name) in the title and I found this great solution from 2013 that still works:

But if the person goes by a single name, for example Banksy, then it appears at the very top but it should appear with the B names. I don't fully understand how the $orderby_statement code works but need to figure out how to set it so that if no ' ' space is found then use the first letter instead?

Ok, I've updated this function. It now works to correctly alphabetize by last word in title but also even if there is only one word.

function posts_orderby_lastname ($orderby_statement) 
{
      $orderby_statement = "RIGHT(post_title, LOCATE(' ', CONCAT(REVERSE(post_title), ' ')) - 1) ASC";

    return $orderby_statement;
}
发布评论

评论列表(0)

  1. 暂无评论