根据类别在 3 个不同的主页位置显示一个自定义 post 类型

Display one custom post type at 3 different home page location based on categories

```$specialmenuItems = new WP_Query(array( 
    'post_type'         => 'special_menu',
    'posts_per_page'    => -1,
));```

这是我的自定义 post 类型(特殊菜单),在管理区域中,此 post 类型分为三个类别(晚餐、饮料和午餐)。主要问题是我们如何根据不同的类别在不同的位置显示此 post 类型?

您需要将类别(它是分类法)添加到 WP_Query:

$specialmenuItems = new WP_Query( array(
    'post_type' => 'special_menu',
    'tax_query' => array(
        array (
            // Here is the taxonomy id
            'taxonomy' => 'category',
            'field' => 'slug',
            // Here you put needed category slug
            'terms' => 'dinner',
        )
    ),
) );

while ( $specialmenuItems->have_posts() ) :
    $specialmenuItems->the_post();
    // Show Posts ...
endwhile;

wp_reset_postdata();