2017-07-26 25 views
-1

我正在使用高级自定义字段和我自定义作者字段(它可能是发布商或品牌等)现在这个作者的名字不打印在产品(书)页上。在自定义字段其作者的名字蛞蝓是“名字”高级自定义字段不返回结果

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');

“的名字”是'作者的自定义字段的字段名称。

+0

是不是更容易地就在这里复制和粘贴文本,在这个问题,不是采取截图,上传到图像托管服务,在此粘贴网址是什么? – axiac

回答

1

试试这个代码ACF

<?php 
echo get_field('your custom filed slug name',get_the_ID()); 
?> 

获取文章标题

<?php echo get_the_title(); ?> 

为显示作者姓名下面的功能

<?php echo get_the_author(); ?> 
+0

无法正常工作。我用“print_r(get_the_ID());”此代码及其打印编号为 – alt4uraj

+0

是的,它是获取id。对于标题使用这个函数echo get_the_title(); –

+0

是这一个工作,我得到了职位的标题,但。 – alt4uraj

0

您可以使用以下方法之一。您必须严格设置$ 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 />"; 
    } 
+0

[link] https://i.stack.imgur.com/tZOcY.jpg这是第二个选项的结果 – alt4uraj

+0

@ alt4uraj您想要获得自定义字段的关键名称? –

+0

我想,你自定义按键名字似乎是“AUTHOR_NAME”,所以替换$ custom_key与“AUTHOR_NAME” –