doudou8081 2014-11-05 00:32
浏览 75
已采纳

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?

  • 写回答

1条回答 默认 最新

  • dougou8552 2014-11-05 02:17
    关注

    For adding new you need to use the create_{$taxonomy} hook

    add_action( 'create_affiche', 'save_affiche_taxonomy_custom_fields', 10, 2 );

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了
  • ¥15 微信小程序商城如何实现多商户收款 平台分润抽成