2016-01-13 88 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中。 –

相關問題