Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正在尝试从另一个自定义帖子获取分类链接_Php_Wordpress_Taxonomy - Fatal编程技术网

Php 正在尝试从另一个自定义帖子获取分类链接

Php 正在尝试从另一个自定义帖子获取分类链接,php,wordpress,taxonomy,Php,Wordpress,Taxonomy,当我试图获取电影导演的分类链接时,我在自定义帖子类型“listing”上列出了所有电影,在自定义帖子类型“directors”上列出了所有导演 <?php $taxonomy ='mydirectors'; $term_lists = get_the_terms($post->ID, $taxonomy); foreach ($term_lists as $termlist): $name_term= $termlist->slug; $argsdirecto

当我试图获取电影导演的分类链接时,我在自定义帖子类型“listing”上列出了所有电影,在自定义帖子类型“directors”上列出了所有导演

<?php

$taxonomy ='mydirectors';
$term_lists = get_the_terms($post->ID, $taxonomy);
foreach ($term_lists as $termlist):
    $name_term= $termlist->slug;
    $argsdirectors = array(
        'post_type' => 'directors',
        'name' => $name_term
        );
    $loop = new WP_Query($argsdirectors);
    if ( $loop->have_posts() ) :
        while($loop->have_posts()): $loop->the_post();
    ?>  <a href="<?php the_permalink() ?>">   <?php 
    $terms = get_the_terms( $post->ID , 'mydirectors' );
    if ( $terms != null ){
        print ' <div class="detail"><span class="name"><font size="+1">Director</font></span><br />';
        foreach( $terms as $term ) {
            print $term->name."<br>" ;
            unset($term);
            if (!empty($terms)) {
                echo "";
            }
        }
        print "</div><br>";
    } 
    ?></a>
    <?php
    endwhile;
    endif;
    endforeach;
    wp_reset_query();
    ?>


有什么问题

尝试将$post->ID替换为get_the_ID(),如下所示:

$terms = get_the_terms( get_the_ID() , 'mydirectors' );

参考资料:

您是否尝试回显$post->ID并查看它的输出?我怀疑你的问题就在那里。谢谢你的回复,但问题还没有解决……非常感谢!我尝试了这个方法,但没有解决我的问题:(使用echo而不是print如何?我尝试了,但没有解决问题。)(如果我替换标签中的文本而不是得到分类名称的php代码,它仍然不起作用。