【问题标题】:Create Custom Post Type from front end template using Advanced Custom Fields使用高级自定义字段从前端模板创建自定义帖子类型
【发布时间】: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' =&gt; 'Post updated.', // default .... to show no message ); 你的 &lt;?php $options = array( 数组没有正确终止。
  • 复制到stackoverflow画面时误报。 (固定)

标签: php wordpress advanced-custom-fields


【解决方案1】:

您是否尝试过(将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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    • 1970-01-01
    • 1970-01-01
    • 2016-06-25
    • 2015-01-11
    • 1970-01-01
    • 2011-12-16
    相关资源
    最近更新 更多