WordPress自定义帖子中的多个查询

问题描述 投票:0回答:1

我有2个CPT:位置和人员。 在每个位置页面上,>>我有一个部分显示在该位置工作的所有人员。

我希望它们由两个字段来组织:

  • 工作人员组(带有#1-6标签的单选按钮)
  • 姓氏
  • 我以为我发现了一些可以按人员组对其进行组织的东西,但是似乎并不是每个页面都在工作。

<?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的早期阶段,因此,非常感谢您的帮助!

我有2个CPT:位置和人员。在每个位置页面上,我都有一个部分,显示在该位置工作的所有人员。我希望它们由两个领域来组织:工作人员小组(a ...

php wordpress custom-wordpress-pages alphabetical
1个回答
0
投票

几件突出的事情:

© www.soinside.com 2019 - 2024. All rights reserved.