按姓氏排序(WP查询和ACF)

我有2个CPT:位置和人员。我将与某个位置相关联的所有人员拉到单个“位置”页面上。当前,它们是由一个名为“ staff_group”的字段(基本上是一个收音机,具有1到15的选项,每个组基于职位)进行排序。但是,在员工团队的价值范围内,我希望能够按姓氏的字母顺序排列。例如,结果将显示第1组的所有姓氏A到Z,然后显示第2组的所有姓氏A到Z,依此类推

示例网格:https://accessphysicaltherapywellness.com/location/goshen-ny/

如何在下面调整我的代码以获得这些结果?

<?php
        /**
         * The Template for displaying single posts.
         */?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
        /*
         *  Query posts for a relationship value.
         *  This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
         */

        $staff = get_posts(array(
            'post_type' => 'people','posts_per_page' => -1,'meta_query'  => array(
                'relation' => 'AND','location_clause' => array(
                    'key' => 'location',// name of custom field
                    'value' => '"' . get_the_ID() . '"',// matches exactly "123",not just 123. This prevents a match for "1234"
                    'compare' => 'LIKE',),'order_clause' => array(
                    'key' => 'staff_group','compare' => 'EXISTS'
                )
            ),'orderby'    => array(
            'order_clause' => 'ASC'
            )
      ));
?>
cengyicang 回答:按姓氏排序(WP查询和ACF)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3147677.html

大家都在问