advanced-custom-fields the_field function not work in wordpress

时间:2018-02-01 18:10:07

标签: wordpress advanced-custom-fields

I'm trying to use the the_field(); function in wordpress but did't work also I tried to use the get_field(); function and same problem what I can do

<?php the_field('contact_form_short_code'); ?>

I am using advanced-custom-fields plugin the free version

3 个答案:

答案 0 :(得分:2)

the_field('contact_form_short_code')将尝试从循环中的当前帖子获取字段信息。如果您当前不在循环中,它将查看当前页面/帖子。

如果您想引用循环外部的帖子,您必须指定帖子ID,例如:the_field('contact_form_short_code', $post_id)

希望有所帮助

答案 1 :(得分:0)

检查您的字段组位置是否指向您的模板,分类或自定义帖子类型,之后尝试使用echo来呼叫您的字段。

点击此链接www.advancedcustomfields.com

答案 2 :(得分:0)

如果要通过自定义字段(ACF)显示管理面板中指定的短代码(contact_form_short_code),则需要使用 do_shortcode(); 功能。
在您的情况下,代码如下所示:

<?php
//In the admin panel we fill the shortcode of the contact form, for example CF7.
//[contact-form-7 id="1" title="Form"] 
$cform = get_field('contact_form_short_code', $post_id);
//Output of shortcode
echo do_shortcode($cform);?>