我想要在前端有一个表单,用于使用 Advanced Custom Fields 创建自定义帖子类型插件。
我正在使用教程 Create A Front End Form 中的代码结合我在 Stack Overflow 上找到的定义 $options
的代码对于 <?php acf_form(); ?>
.
到目前为止我的代码是:
<?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 等?
最佳答案
您是否尝试过(将 88
设置为您的字段组 ID)
<?php $options = array(
'post_id' => $id,
'field_groups' => array(88 ), // this is the ID of the field group
....
也许这会有所帮助
How to edit a user profile on the front end
Front end post editing using a form
acf-edit-title-content
关于php - 使用高级自定义字段从前端模板创建自定义帖子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23744208/