显示元字段 PHP WP

Display Meta Fields PHP WP

我正在使用类别和分类法元字段 pluginproduct categories 中创建一些必要的字段。

当试图在 php 中显示此信息时,它没有出现。

$cate = get_queried_object();
$cateID = $cate->term_id;
if (function_exists('get_all_wp_terms_meta'))
{ 
   print_r( get_all_wp_terms_meta($cateID) );
}

archive-product.php 页,return Array ( )

使用插件Advanced Custom Fields

在文件 archive-product.php 中使用:

$cateID = get_queried_object();
$return = get_field('NameField', $cateID);

如果使用灵活字段,请在字段设置中命名布局并使用

if ( have_rows( 'NameItem', $cateID ) ) :
    while ( have_rows( 'NameItem', $cateID ) ) : the_row();
        if( get_row_layout() == 'NameLayout' ):
            echo get_sub_field('NameFiel');
         endif;
    endwhile;
else :