【问题标题】:how to display wordpress acf custom fields in front end form posting如何在前端表单发布中显示 wordpress acf 自定义字段
【发布时间】:2014-03-20 20:33:55
【问题描述】:

在我的项目中,我需要在前端显示自定义帖子字段表单,所以我已经安装了 ACF 并创建了自定义字段,现在我的问题是如何将这些字段与 HTML 一起呈现????我使用了 get_fields() 函数,但它仍然不会显示任何 HTML 代码。

【问题讨论】:

  • 你是如何使用 get_fields() 的?给我们看..

标签: php wordpress advanced-custom-fields


【解决方案1】:

看看这个Documents...

您可以使用以下功能添加字段或完整表单,

$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 );

希望对您有所帮助...

【讨论】:

  • 您好,感谢您帮助我,但这是我的要求。我创建了一个自定义字段组..我允许用户从 FF 创建帖子,所以当用户创建新帖子时,我希望这些字段对用户可见...
【解决方案2】:

如果要在帖子中显示字段,则必须将代码放在“single.php”的循环中,假设您使用的是标准帖子类型。

此代码仅检索字段,它不会显示任何内容,它用于将值存储在变量中:

get_field('field-name');

要使字段显示在模板中,您必须使用以下内容:

the_field('field-name');

您还可以在存档模板中插入代码或查询您正在使用的帖子来显示帖子。

这也可以:

echo get_field('field-name')

或

$myfield = get_field('field-name');
echo $myfield;

【讨论】:

    【解决方案3】:

    您可以使用 ACF 前端显示插件: https://wordpress.org/plugins/acf-frontend-display

    在帖子或页面编辑中选中“显示在前面”。

    如果您想添加一些操作,请尝试使用表单操作插件: https://wordpress.org/plugins/forms-actions/

    【讨论】:

      【解决方案4】:

      全部在that document解释

      另外,还有一个函数here 可以帮助你

      【讨论】:

        【解决方案5】:

        在您的模板中添加该代码:

        <?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
        

        【讨论】:

        • 感谢队友.. 缺少 acf_form_head - gr8 帮助 ;)
        猜你喜欢
        • 2021-07-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-16
        • 2021-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多