我试图在发布或更新自定义帖子类型(“film”)时设置自定义字段的值。最终目标是在发布或更新帖子时,根据URL字段从API获取元数据。
我试着用add_action( \'save_post_film\', \'get_film_data\', 10, 2 );
, 具有以下功能:
function get_film_data( $post_id ) {
// If this is just a revision, don\'t send the email.
if ( wp_is_post_revision( $post_id ) )
return;
$value = \'something\'; // The value depends in fact on the value of another field
update_post_meta($post_id, \'some_custom_field\', $value);
}
这仅在创建新帖子时有效。编辑表单打开时,自定义字段的值已设置。但由于某种原因,这篇文章一发表就行不通了。我做错了什么?