Php 我需要知道我的代码有什么问题,我正在尝试获取所有与之相关的子类别和帖子
现在,我正在努力获取所有与其子类别相关的帖子 我使用此代码检查分类法是否为父分类法 但问题是它没有显示我只收到帖子的子类别 所以 我怎样才能得到所有的子类别和与之相关的帖子Php 我需要知道我的代码有什么问题,我正在尝试获取所有与之相关的子类别和帖子,php,wordpress,Php,Wordpress,现在,我正在努力获取所有与其子类别相关的帖子 我使用此代码检查分类法是否为父分类法 但问题是它没有显示我只收到帖子的子类别 所以 我怎样才能得到所有的子类别和与之相关的帖子 $term=get_queryed_object(); 如果($term->post_parent!=0){ //echo“有父项”;//此帖子类别有子项 $term\u id=$term->term\u id; $taxonomy\u name=$term->taxonomy; $termchildren=get_term
$term=get_queryed_object();
如果($term->post_parent!=0){
//echo“有父项”;//此帖子类别有子项
$term\u id=$term->term\u id;
$taxonomy\u name=$term->taxonomy;
$termchildren=get_term_children($term_id,$taxonomy_name);
//echo$Postat;
foreach($termchildrenas$child){
$term=get_term_by('id',$child,$taxonomy_name);
?>
//获取子类别的数据
$term = get_queried_object();
if($term->post_parent !=0 ){
// echo 'has parent'; //this post category has child
$term_id = $term->term_id;
$taxonomy_name = $term->taxonomy;
$termchildren = get_term_children( $term_id, $taxonomy_name );
// echo $postcat ;
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child, $taxonomy_name );
?>
// get data of the subcategory
<?php }?>
<?php }
else{
while(have_posts()):the_post();
// get the subcategory posts
<?php endwhile ?>
<?php }?>