2016-01-13 91 views
0

如何将我的ACF字段添加到另一个插件的形式?如何将我的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> 

将如何实现这一目标?

+0

这不是正确的解决方案,它会为你提供BUSINESS_NAME的价值...请访问此链接进行了详细的解决方案:http://www.advancedcustomfields.com/resources/create-a-前端形式/ –

+0

好吧,让我看看它。 –

+0

我必须添加的字段应该与产品相关联。在后台我有表单。当我从前端添加一个产品时,它的值也应该在后端可见,坚果我无法做到。 –

回答

1

创建一个新的模板,并将其赋值给一个网页..

在模板拷贝

下面这段代码:

你必须改变2个东西在下面的代码1. YOUR_POST_TYPE,2.您 场组

场组可以通过编辑任何场组来实现(其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(); ?> 
+0

其实我必须在wc deals插件中插入字段。所以我只是复制这个代码在那里的HTML部分? –

+0

如果您只希望从前端插入一个字段,然后手动创建一个html输入标记并将记录插入到所需的表格中。 请在Wp_posts https://codex.wordpress.org中找到要添加记录的链接/ Function_Reference/wp_insert_post 在wp_post_meta中插入记录https://codex.wordpress.org/Function_Reference/add_post_meta –

+0

是的,我知道如何添加单个字段,但我的场景有点不同。我在后端的产品中添加了组字段(通过ACF)。我希望这些确切的字段也可以在前端(只需传递他们的id或其他内容)并将其值保存在ACF中。 –

相关问题