如何将我的ACF字段添加到另一个插件的表单中

时间:2016-01-13 04:48:36

标签: wordpress

如何将我的ACF字段添加到另一个插件的表单中?

我试过了,但这不起作用

<div class="input-group">
    <label for="deal_title"><?php _e('Deal title', 'wcd'); ?> <span class="required">*</span></label>
    <input type="text" name="deal_title" id="deal_title" value="<?php echo esc_attr($deal_title) ?>" class="form-control" data-validation="required"  data-error="<?php esc_attr_e('Please input deal description', 'wcd'); ?>">
    <p class="description"><?php _e('Input title for the deal.', 'wcd'); ?></p>
</div>

//This is the part I want my ACF field
<?php echo the_field('business_name'); ?>

<div class="input-group">
    <label for="deal_description" data-error="<?php esc_attr_e('Please type description of the deal', 'wcd'); ?>"><?php _e('Deal Description', 'wcd'); ?> <span class="required">*</span></label>
    <?php wp_editor($deal_description, 'deal_description'); ?>
    <p class="description"><?php _e('Input description of the deal.', 'wcd'); ?></p>
</div>

如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

创建一个新模板并将其分配给页面..

现在在该模板中复制此代码:

  

您必须在以下代码中更改2件事.YOUR_POST_TYPE,2。您的   FIELD GROUP

可以通过编辑任何字段组来实现字段组(其ID将位于顶部)。

<?php acf_form_head(); ?>
<?php get_header(); ?>

<?php 
function my_pre_save_post( $post_id )
{
    // check if this is to be a new post
    if( $post_id != 'new' )
    {
        return $post_id;
    }

    // Create a new post
    $post = array(
        'post_status'  => 'publish' ,
        'post_title'  => $_POST['fields']['title'] ,
        'post_type'  => 'YOUR_POST_TYPE' ,
    );  

    // insert the post
    $post_id = wp_insert_post( $post ); 

    // update $_POST['return']
    $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    

    // return the new ID
    return $post_id;
}

add_filter('acf/pre_save_post' , 'my_pre_save_post' );
?>
            <div id="content" class="clearfix row">

                <div id="main" class="col-sm-12 clearfix" role="main">

                    <?php 
                    acf_form(array(
                        'field_groups'        => array('YOUR FIELD GROUP'),
                        'post_id'       => 'new',
                        'submit_value'      => 'Submit Product'
                )); ?>

                </div> <!-- end #main -->

                <?php //get_sidebar(); // sidebar 1 ?>

            </div> <!-- end #content -->

<?php get_footer(); ?>