【发布时间】:2019-10-14 16:00:30
【问题描述】:
我有 2 个 CPT:位置和人员。 在每个位置页面上,我都有一个部分显示在该位置工作的所有人员。
我希望它们按两个字段进行组织:
- 员工组(标签为 #1-6 的单选按钮)
- 姓氏
我以为我找到了按员工组组织它们的东西,但它似乎并不是在每个页面上都有效。
- 正确顺序(导演、治疗师、助理、定制服务专家/助理):https://aptw.nk-creative.com/location/goshen-ny/
- 顺序错误(导演接近尾声):https://aptw.nk-creative.com/location/woodstock-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(
'location_clause' => 'ASC',
'order_clause' => 'ASC')
)
);
?>
我仍处于学习自定义 WP 的早期阶段,因此非常感谢任何帮助!
【问题讨论】:
标签: php wordpress custom-wordpress-pages alphabetical