【发布时间】:2014-07-07 19:04:29
【问题描述】:
我想要一个在前端使用Advanced Custom Fields 插件创建自定义帖子类型的表单。
我正在使用教程 Create A Front End Form 中的代码以及我在 Stack Overflow 上找到的代码,该代码为 <?php acf_form(); ?> 定义了 $options。
我目前的代码是:
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
$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' => 'submit',
'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' => 'Submit', // value for submit field
'updated_message' => 'Post updated.', // default updated message. Can be false to show no message
);
acf_form( $options );
?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
我不确定如何完成这项工作:
- 如何指定帖子 ID?
- 如何/在哪里指定与自定义帖子类型和我要显示的自定义字段的连接?
您能否告诉我在代码中的何处可以获取我的字段 ID 等特定信息?
【问题讨论】:
-
为什么你有这个声明发表了评论。 ?
);在这一行'updated_message' => 'Post updated.', // default .... to show no message );你的<?php $options = array(数组没有正确终止。 -
复制到stackoverflow画面时误报。 (固定)
标签: php wordpress advanced-custom-fields