Wordpress - 保存自定义分类的自定义字段数据
Forgive me if this answer is easily found in the Codex function reference. I have looked at the reference page for add_action( $hook, $function_to_add, $priority, $accepted_args );
but I have not been able to find the information I need.
What I have already:
I've created a custom field for my custom taxonomy of a custom post type. This custom field is added both to the "add new" and "edit" contexts (see image links):
Yay, the creation part works!
What doesn't work:
Unfortunately, I'm only able to save media links that added using the "edit" context. Media links added using the "add new" quick create tool are not being saved.
Why it doesn't work
If I take a look at the example I followed to create my custom meta field (https://pippinsplugins.com/adding-custom-meta-fields-to-taxonomies/) you'll see that Pippin does not include a save action for the "add new" part, he only adds the field using add_action( 'category_add_form_fields', 'pippin_taxonomy_add_new_meta_field', 10, 2 );
I know that what I am missing is the WordPress specific syntax for saving actions in the "add new" context, and I know that it will be similar to the save action which is used for the "edit" context:
// add custom field to 'edit' and 'add new' contexts
add_action( 'affiche_edit_form_fields', 'affiche_taxonomy_custom_fields', 10, 2 );
add_action( 'affiche_add_form_fields', 'affiche_taxonomy_custom_fields', 10, 2 );
// save field input
add_action( 'edited_affiche', 'save_affiche_taxonomy_custom_fields', 10, 2 );
Reviewing the last line of the above code block, what is the equivalent string to 'edited_[taxonomy_name]'
for adding new (not editing existing) custom taxonomy entries?
如果在Codex函数参考中很容易找到这个答案,请原谅我。 我查看了 我已经拥有的内容: strong> p>
我为自定义帖子类型的自定义分类创建了自定义字段。 此自定义字段将添加到“添加新”和“编辑”上下文中(请参见图像链接): p>
是的,创作部分有效! p>
什么行不通: strong> p>
不幸的是,我只能保存使用“编辑”添加的媒体链接 “背景。 使用“添加新”快速创建工具添加的媒体链接未保存。 p>
为什么不起作用 strong> p>
如果我看一下我创建自定义元字段的示例( https://pippinsplugins.com/adding-custom-meta-fields-to-taxonomies/ )你会发现Pippin不包含“添加新”部分的保存操作,他只添加了 字段使用 我知道我缺少的是 用于在“添加新”上下文中保存操作的WordPress特定语法,我知道它将类似于用于“编辑”上下文的保存操作: p>
查看上面代码块的最后一行, strong> add_action($ hook,$ function_to_add,$ priority,$ accepted_args); code>的参考页面,但我找不到我需要的信息。 p>
\ n
add_action('category_add_form_fields','pippin_taxonomy_add_new_meta_field',10,2); code> p>
//将自定义字段添加到“编辑”和“添加新”上下文
add_action('affiche_edit_form_fields','affiche_taxonomy_custom_fields',10,2);
add_action('affiche_add_form_fields','af fiche_taxonomy_custom_fields',10,2);
//保存字段输入
add_action('edited_affiche','save_affiche_taxonomy_custom_fields',10,2);
code> pre>
'edited_ [taxonomy_name]' code> 的等效字符串是什么,用于添加新的(不是编辑现有的)自定义分类条目 ? strong> p>
div>
For adding new you need to use the create_{$taxonomy}
hook
add_action( 'create_affiche', 'save_affiche_taxonomy_custom_fields', 10, 2 );