WordPress Orderby Last Word In Title

北城以北 提交于 2019-12-04 05:04:50

Try this. First add the following orderby filter in functions.php

function posts_orderby_lastname ($orderby_statement) 
{
  $orderby_statement = "RIGHT(post_title, LOCATE(' ', REVERSE(post_title)) - 1) DESC";
    return $orderby_statement;
}

and then use it in your query like so

add_filter( 'posts_orderby' , 'posts_orderby_lastname' );
    $loop = new WP_Query(
        array (
            'post_type' => 'staff',
            'staff-type' => $type
        )
    );

and after the loop remove the filter

remove_filter( 'posts_orderby' , 'posts_orderby_lastname' );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!