如何在前端表单发布中显示wordpress acf自定义字段

问题描述 投票:3回答:5

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

php wordpress advanced-custom-fields
5个回答
1
投票

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

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

get_field('field-name');

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

the_field('field-name');

您还可以将代码插入到用于显示帖子的存档模板或查询帖子中。

这也可行:

echo get_field('field-name')

要么

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

1
投票

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

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

如果你想添加一些动作,请尝试使用Forms动作插件:https://wordpress.org/plugins/forms-actions/


1
投票

添加该代码不是您的模板:

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

0
投票

所有都在that document解释

此外,还有一个功能here将帮助您


0
投票

看看这个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 );

希望对你有帮助...

© www.soinside.com 2019 - 2024. All rights reserved.