对于“成员”页面,我有4个自定义分类法,其中包含多个术语。我有一个“位置”和“组织”的分类法,我正试图将其分为一个列表。我需要按照“组织”分类法中的“aba治疗师”一词来获取所有帖子,并按照它们的“位置”来分隔这些帖子如果这对任何人都有意义的话。类似这样:
ABA治疗师组织分类学术语
位置分类学第2学期
位置分类学第3学期
这就是我所拥有的代码,它只会吸引“成员”CPT中的每个帖子,并按每个学期组织:
foreach ($taxonomies as $taxonomy){
$terms = get_terms($taxonomy, array(\'orderby\' => \'date\', \'order\' => \'ASC\'));
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
$args = array(
\'post_type\' => $post_type,
\'orderby\' => \'date\',
\'order\' => \'ASC\',
\'ignore_sticky_posts\' => 1,
\'post_status\' => \'publish\',
\'posts_per_page\' => - 1,
\'tax_query\' => array(
array(
\'taxonomy\' => $taxonomy,
\'field\' => \'slug\',
\'terms\' => $term->slug
)
)
);
$my_query = null;
$my_query = new WP_Query($args);
if ($my_query->have_posts()) {
echo \'<div class="members"><div class="wrap"><h3>\' . $term->name . \'</h3></div><div class="details"><div class="wrap">\';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail(\'cac-small\'); ?>
<?php else : ?>
<img src="<?php echo get_template_directory_uri(); ?>/img/profile-placeholder.png" alt="Default Image">
<?php endif; ?>
<div class="caption">
<p><?php the_title(); ?></p>
</div>
</a>
<?php
endwhile;
} // END if have_posts loop
echo \'</div></div></div>\'; // Close \'details\', \'wrap\', & \'members\' DIVs
wp_reset_query();
} // END foreach $terms
}
}
?>
我不知道从哪里开始。有人有线索吗?
最合适的回答,由SO网友:sabarnix 整理而成
$terms = get_terms(\'location\', array(\'orderby\' => \'date\', \'order\' => \'ASC\'));
foreach( $terms as $term ) {
$args = array(
\'post_type\' => $post_type,
\'orderby\' => \'date\',
\'order\' => \'ASC\',
\'ignore_sticky_posts\' => 1,
\'post_status\' => \'publish\',
\'posts_per_page\' => - 1,
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'organize\',
\'field\' => \'slug\',
\'terms\' => array( \'aba-therapist\' )
),
array(
\'taxonomy\' => \'location\',
\'field\' => \'slug\',
\'terms\' => array( $term->slug )
)
)
);
$my_query = new WP_Query($args);
if ($my_query->have_posts()) {
echo \'<div class="members"><div class="wrap"><h3>\' . $term->name . \'</h3></div><div class="details"><div class="wrap">\';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail(\'cac-small\'); ?>
<?php else : ?>
<img src="<?php echo get_template_directory_uri(); ?>/img/profile-placeholder.png" alt="Default Image">
<?php endif; ?>
<div class="caption">
<p><?php the_title(); ?></p>
</div>
</a>
<?php
endwhile;
} // END if have_posts loop
wp_reset_postdata();
}
希望这段代码为你填充工作。在上方添加ABA治疗师标题。