php 具有自定义分类类别的自定义帖子类型
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 具有自定义分类类别的自定义帖子类型相关的知识,希望对你有一定的参考价值。
<?php
// this custom post type uses a custom taxonomy for categories, not using the regular post categories
// to get the categories assigned for each post, need to use get_the_terms( post_ID, 'your-taxonomy-name' )
$args = [
'post_type' => 'treatment',
'post_status' => 'publish',
'order' => 'ASC'
];
$treatment = new WP_Query( $args );
if( $treatment->have_posts() ) :
while( $treatment->have_posts() ) :
$treatment->the_post();
?>
<div class="treatment-container">
<div class="treatment-title">Title: <?php echo $post->post_title ; ?></div>
<div>Post Type: <?php echo $post->post_type; ?></div>
<div>POST ID: <?php echo $post->ID ; ?></div>
<div>Category:
<?php
$terms = get_the_terms( $post->ID, 'treatment_category' );
foreach ( $terms as $term )
echo $term->name .'<br>';
?>
</div>
<hr>
</div>
<?php
endwhile;
wp_reset_postdata(); ?>
<?php
else :
esc_html_e( 'Treatments N/A', 'text-domain' );
endif;
?>
以上是关于php 具有自定义分类类别的自定义帖子类型的主要内容,如果未能解决你的问题,请参考以下文章