添加文章时自动添加文章
问题描述:
我正在使用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”中。我不知道要编辑哪个文件。
答
您需要使用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
没有明确的,你想达到什么样的,请解释多一点并尽可能添加屏幕截图 –
谢谢。 我想使用php代码链接一个类别和一个帖子。但是我没有找到这个文件。 上面的ACF用于创建字段,提交后我想链接一个类别和在上述字段中选择的帖子。 – santosh433
你的意思是你想要指定类别的职位? –