Как сохранить добавленное поле acf_add_local_field в ACF? - PullRequest
0 голосов
/ 27 октября 2018

Таким образом, я сгенерировал поле повторителя в своем пользовательском типе записи, который представляет собой продукты, но когда я попытался сохранить некоторые данные и обновить страницу, они не сохраняются.

На форуме acf есть код, в котором вы можете сохранить значение поля повторителя, например:

   // save a repeater field value
   $field_key = "field_12345678";
   $value = array(
   array(
     "sub_field_1"  => "Foo",
     "sub_field_2"  => "Bar"
    )
 );
 update_field( $field_key, $value, $post_id );

Но я не уверен, где можно взять поле $value в моем случае.

Вот мой код:

<code>function wpt_add_product_metaboxes() {
global $post;
$unique_terms = array(); 
$postID              =   $post->ID;
$have_terms          =   get_the_terms($postID, 'product_attributes');

if($have_terms):
    $parent_terms  = wp_get_post_terms( $postID,'product_attributes', array( 'parent' => 0, 'orderby' => 'id', 'order' => 'DESC', 'hide_empty' => false ) );    
    #print("<pre>".print_r($parent_terms,true)."
"); $ ctr = 0; foreach ($ parent_terms как $ p_term): $ custom_taxnomies_child = wp_get_post_terms ($ postID, 'product_attributes', массив ('parent' => 66, 'orderby' => 'slug', 'hide_empty' => false)); foreach ($ custom_taxnomies_child как $ cterm) { if (! in_array ($ cterm-> term_id, $ unique_terms)) { array_push ($ unique_terms, $ cterm-> term_id); $ ЕГО ++; acf_add_local_field (массив ( 'key' => 'field_tab_size _'. $ ctr, 'label' => $ cterm-> name, 'name' => 'store_sizes _'. $ ctr, 'type' => 'tab', 'parent' => 'field_5bd14c9349930', 'инструкция' => '', 'required' => 0, 'conditional_logic' => 0, 'обертка' => массив ( 'ширина' => '', 'class' => '', 'id' => '', ), 'collapsed' => '', 'min' => '', 'max' => '', )); / ** * Начальное поле повторителя * * / acf_add_local_field (массив ( 'key' => 'field_product_sizes_prices'. $ ctr, 'label' => 'Размеры и цены товара', 'name' => 'product_sizes _'. $ ctr, 'type' => 'repeater', 'parent' => 'field_5bd14c9349930', 'инструкция' => '', 'required' => 0, 'conditional_logic' => 0, 'обертка' => массив ( 'ширина' => '', 'class' => '', 'id' => '', ), 'collapsed' => '', 'min' => '', 'max' => '', 'layout' => 'table', 'button_label' => 'Добавить строку' )); / ** * Добавить подполе даты начала * * / acf_add_local_field (массив ( 'key' => 'field_total_products _'. $ ctr, 'label' => 'Total Products', 'name' => 'total_products'. $ ctr, 'parent' => 'field_product_sizes_prices'. $ ctr, // ключ родительского повторителя 'type' => 'text', 'инструкция' => '', )); / ** * Добавить подполе Дата окончания * * / acf_add_local_field (массив ( 'key' => 'field_total_prices _'. $ ctr, 'label' => 'Всего цен', 'name' => 'total_prices', 'parent' => 'field_product_sizes_prices'. $ ctr, 'type' => 'text', )); } endforeach; ENDIF; }
...