カスタム投稿タイプからカテゴリのタイトルとその投稿を表示しようとしています。表示するカテゴリを取得できますが、現在、カスタム投稿領域内のすべての投稿をリストするのではなく、
<?php
$taxonomy = 'staff';
$cat_args = array(
'taxonomy' => $taxonomy,
'tax_input' =>$tax_input,
'orderby' => 'name',
'order' => 'ASC',
'child_of' => 0
);
$tax_terms = get_terms($taxonomy);
foreach ($tax_terms as $tax_term) {
echo '<div class="categorybox">';
echo '<h4> <a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></h4>';
$args = array(
'post_type' => 'staff',
"singular_label" => "Department",
'numberposts' => 5,
'taxonomy' => $taxonomy->$tax_term,
);
$posts = get_posts($args);
?>
<ul><?php
foreach($posts as $post) {
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
} ?>
</ul><?php
echo '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>View all articles in ' . $tax_term->name.' »</a>';
echo '</div>';
}
?>