2016-05-17 93 views
0

我正在使用WordPress的新聞網站。 有以下ACF代碼稱爲標題的地方。其中添加帖子到網站的標題。添加文章時自動添加文章

array (
         'key' => 'field_53e3e2fc67dc4', 
         'label' => 'Headlines', 
         'name' => 'hp_headlines', 
         'prefix' => '', 
         'type' => 'repeater', 
         'instructions' => '', 
         'required' => 0, 
         'conditional_logic' => 0, 
         'wrapper' => array (
          'width' => '', 
          'class' => '', 
          'id' => '', 
         ), 
         'min' => '', 
         'max' => '', 
         'layout' => 'row', 
         'button_label' => 'Add Headline', 
         'sub_fields' => array (
          array (
           'key' => 'field_54621f720bfdc', 
           'label' => 'Headline Type', 
           'name' => 'hp_headline_type', 
           'prefix' => '', 
           'type' => 'radio', 
           'instructions' => '', 
           'required' => 1, 
           'conditional_logic' => 0, 
           'wrapper' => array (
            'width' => '', 
            'class' => '', 
            'id' => '', 
           ), 
           'choices' => array (
            'url' => 'URL', 
            'article' => 'Article', 
           ), 
           'other_choice' => 0, 
           'save_other_choice' => 0, 
           'default_value' => 'url', 
           'layout' => 'horizontal', 
          ), 
          array (
           'key' => 'field_54621fa20bfdd', 
           'label' => 'URL', 
           'name' => 'hp_headline_url', 
           'prefix' => '', 
           'type' => 'url', 
           'instructions' => '', 
           'required' => 1, 
           'conditional_logic' => array (
            array (
             array (
              'field' => 'field_54621f720bfdc', 
              'operator' => '==', 
              'value' => 'url', 
             ), 
            ), 
           ), 
           'wrapper' => array (
            'width' => '', 
            'class' => '', 
            'id' => '', 
           ), 
           'default_value' => '', 
           'placeholder' => 'http://', 
          ), 
          array (
           'key' => 'field_53e3e34067dc5', 
           'label' => 'Article', 
           'name' => 'hp_headline_article', 
           'prefix' => '', 
           'type' => 'post_object', 
           'instructions' => '', 
           'required' => 1, 
           'conditional_logic' => array (
            array (
             array (
              'field' => 'field_54621f720bfdc', 
              'operator' => '==', 
              'value' => 'article', 
             ), 
            ), 
           ), 
           'wrapper' => array (
            'width' => '', 
            'class' => '', 
            'id' => '', 
           ), 
           'post_type' => array (
            0 => 'post', 
           ), 
           'taxonomy' => '', 
           'allow_null' => 0, 
           'multiple' => 0, 
           'return_format' => 'id', 
           'ui' => 1, 
          ),        
         ), 

它創建一個字段,將已添加的帖子添加到標題列表中。 現在我希望這些字段在我按下更新按鈕時自動添加到類別「xyz」中。我不知道要編輯哪個文件。

enter image description here

+0

沒有明確的,你想達到什麼樣的,請解釋多一點並儘可能添加屏幕截圖 –

+0

謝謝。 我想使用php代碼鏈接一個類別和一個帖子。但是我沒有找到這個文件。 上面的ACF用於創建字段,提交後我想鏈接一個類別和在上述字段中選擇的帖子。 – santosh433

+0

你的意思是你想要指定類別的職位? –

回答

4

您需要使用save_post行動,在你的functions.php變貓ID機智添加該代碼的類別ID的

function set_my_categories($post_ID){ 
    if(wp_is_post_autosave($post_ID) || wp_is_post_revision($post_ID)) { 
    return $post_ID; 
    } 
    wp_set_post_categories($post_ID, array(49,13)); 
    } 
    add_action('save_post', 'set_my_categories'); 
+0

謝謝你的幫助。我會嘗試這個並回來。 – santosh433