php 如何在前端表单发布中显示 wordpress acf 自定义字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21898672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to display wordpress acf custom fields in front end form posting
提问by user1452840
In my project I need to display custom post fields form on front end , so I have installed ACF and created custom filed , now my issue is how to render these fields along with the HTML ???? I used get_fields() function , still it won't display any HTML code .
在我的项目中,我需要在前端显示自定义帖子字段表单,所以我已经安装了 ACF 并创建了自定义文件,现在我的问题是如何将这些字段与 HTML 一起呈现????我使用了 get_fields() 函数,它仍然不会显示任何 HTML 代码。
回答by Reitz
If you want to show the fields inside the post, you have to place the code inside the loop of "single.php", supposing you are using the standard post type.
如果要显示帖子内的字段,则必须将代码放在“single.php”循环内,假设您使用的是标准帖子类型。
This code retrive the field only, it won't show anything, it's used to store the value in a variable:
此代码仅检索字段,它不会显示任何内容,它用于将值存储在变量中:
get_field('field-name');
To make the fields show in the template you have to use the following:
要使字段显示在模板中,您必须使用以下内容:
the_field('field-name');
You can also insert the code in the archive template or query post your are using to show posts.
您还可以在存档模板或查询帖子中插入代码以显示帖子。
This also would work:
这也可以:
echo get_field('field-name')
or
或者
$myfield = get_field('field-name');
echo $myfield;
回答by user3719894
You could use ACF Frontend display plugin: https://wordpress.org/plugins/acf-frontend-display
您可以使用 ACF 前端显示插件:https: //wordpress.org/plugins/acf-frontend-display
Check "display on front" within post or page editing.
在帖子或页面编辑中选中“显示在前面”。
If you want add some actions try to use Forms actions plugin: https://wordpress.org/plugins/forms-actions/
如果您想添加一些操作,请尝试使用 Forms 操作插件:https: //wordpress.org/plugins/forms-actions/
回答by Nims Patel
Add that code no your template :
添加该代码没有您的模板:
<?php
/**
* Template Name: Resume Build
*
* @package Betheme
* @author Muffin Group
*/
?>
<?php
/**
* The main template file.
*
* @package Betheme
* @author Muffin group
* @link http://muffingroup.com
*/
acf_form_head();
get_header();
?>
<!-- #Content -->
<div id="Content">
<div class="content_wrapper clearfix">
<!-- .sections_group -->
<div class="sections_group">
<div id="content">
<?php
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => false,
'new_post' => array(
'post_type' => 'resume',
'post_status' => 'publish'
)
));
?>
</div>
</div>
<!-- .four-columns - sidebar -->
<?php get_sidebar( 'blog' ); ?>
</div>
</div>
<?php get_footer();
// Omit Closing PHP Tags
回答by Feyrisa
All is explain in that document
一切都在该文件中说明
Plus, there is a function herewhich will help you
此外,还有一个功能,在这里,这将帮助你
回答by Aksh?y Paghdar
Have a look at this Documents...
看看这个文件...
You can add fields or full form with following function,
您可以使用以下功能添加字段或完整表格,
$options = array(
'post_id' => $post->ID, // post id to get field groups from and save data to
'field_groups' => array(), // this will find the field groups for this post (post ID's of the acf post objects)
'form' => true, // set this to false to prevent the <form> tag from being created
'form_attributes' => array( // attributes will be added to the form element
'id' => 'post',
'class' => '',
'action' => '',
'method' => 'post',
),
'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
'html_before_fields' => '', // html inside form before fields
'html_after_fields' => '', // html inside form after fields
'submit_value' => 'Update', // value for submit field
'updated_message' => 'Post updated.', // default updated message. Can be false to show no message
);
acf_form( $options );
Hope this will help you...
希望能帮到你...

