Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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 Can';无法在WordPress上获取foreach中的post#u custome(';项';)_Php_Wordpress - Fatal编程技术网

Php Can';无法在WordPress上获取foreach中的post#u custome(';项';)

Php Can';无法在WordPress上获取foreach中的post#u custome(';项';),php,wordpress,Php,Wordpress,我在WordPress中使用自定义帖子类型。我想显示主要类别、次要类别和与次要类别关联的自定义帖子 问题在于,尽管显示了,但post\u custom('price')不起作用。我不明白为什么它不起作用 <?php $my_tax = 'area'; $parent_terms = get_terms( $my_tax, array('hide_empty' => false, 'parent' => 0) ); //第一階層のタームだけ取得 if ( !em

我在WordPress中使用自定义帖子类型。我想显示主要类别、次要类别和与次要类别关联的自定义帖子

问题在于,尽管显示了
,但
post\u custom('price')
不起作用。我不明白为什么它不起作用

<?php 
  $my_tax = 'area'; 
  $parent_terms = get_terms( $my_tax, array('hide_empty' => false, 'parent' => 0) );  //第一階層のタームだけ取得
  if ( !empty( $parent_terms ) ) :
    echo '<ul>';
    foreach ( $parent_terms as $pt ) : 
      $pt_id = $pt->term_id;
      $pt_name = $pt->name;
      $pt_url = get_term_link($pt);
?>

    <?php 
        $child_terms = get_terms( $my_tax, array('hide_empty' => false, 'parent' => $pt_id) );
        if ( !empty( $child_terms ) ) :
        echo '<ul class="child">';
        foreach ( $child_terms as $ct ) : 
            $ct_id = $ct->term_id;
            $ct_name = $ct->name;
            $ct_url = get_term_link($ct);?>  

            // It worked
            <p><?php the_title(); ?></p>

            // Doesn't work
            <p><?php echo post_custom('price'); ?></p>
    <?php
        endforeach;
        echo '</ul>';
        endif;
    ?>

<?php
    endforeach; 
    echo '</ul>';
  endif;
?>

//它起作用了

//不起作用