高级自定义字段不返回结果
我正在使用高级自定义字段和我自定义作者字段(它可能是发布商或品牌等)现在这个作者的名字不打印在产品(书)页上。在自定义字段其作者的名字蛞蝓是“名字”高级自定义字段不返回结果
add_action('woocommerce_after_single_product_summary', "ACF_product_content", 10);
function ACF_product_content(){
echo '<h2> ACF Content </h2>';
if (function_exists('the_field')){
echo '<p>Woohoo, the_field function exists! </p>';
//the_field('authors');
echo '<pre>';
print_r(get_the_ID());
echo '</pre>';
echo '<pre>';
print_r(get_field('authors'));
echo '</pre>';
die;
}
}
为了这个,我得到的结果 Check this report screenshot 。现在的问题是在这个数组中显示['post_title']的作者姓名。 我尝试了很多解决方案,但没有工作,没有显示出结果。 我使用这个代码来显示这个结果
echo the_field('names');
“的名字”是'作者的自定义字段的字段名称。
试试这个代码ACF
<?php
echo get_field('your custom filed slug name',get_the_ID());
?>
获取文章标题
<?php echo get_the_title(); ?>
为显示作者姓名下面的功能
<?php echo get_the_author(); ?>
您可以使用以下方法之一。您必须严格设置$ post,否则get_the_ID()
函数返回false
。
global = $post;
$custom_key = 'author';
$post_id = get_the_ID();
echo $customer_key_value = get_post_meta($post_id, $custom_key , true);
OR
global = $post;
$custom_key = 'author';
$post_id = get_the_ID();
$custom_values = get_post_custom_values($custom_key , $post_id);
foreach ($custom_values as $key => $value) {
echo "$key => $value <br />";
}
[link] https://i.stack.imgur.com/tZOcY.jpg这是第二个选项的结果 – alt4uraj
@ alt4uraj您想要获得自定义字段的关键名称? –
我想,你自定义按键名字似乎是“AUTHOR_NAME”,所以替换$ custom_key与“AUTHOR_NAME” –
是不是更容易地就在这里复制和粘贴文本,在这个问题,不是采取截图,上传到图像托管服务,在此粘贴网址是什么? – axiac