我需要帮助防止自定义字段在第一次发布后被更新。
我有一些帖子,其中有一个mp3文件的链接和该文件的描述。发布时,我有一个函数,可以从内容中删除指向mp3文件的链接,并将其添加到一个名为audio_url
.
如果我更改帖子,自定义字段中的mp3链接将被删除。
my中的代码functions.php
:
function save_url_link( $post_id, $post ){
if ( has_post_format(\'audio\', $post_id)) {
if (! wp_is_post_revision( $post_id ) ){
preg_match_all ( "/(http|https):\\/\\/.*\\/(.*)\\.(mp3|m4a|ogg|wav|wma)/", $post->post_content, $matches );
update_post_meta( $post_id, \'audio_url\', $matches[0][0] );
}
remove_action(\'save_post\', \'save_url_link\', 10, 2);
wp_update_post(array(\'ID\' => $post_id, \'post_content\' => preg_replace(\'/(http|https):\\/\\/.*\\/(.*)\\.(mp3|m4a|ogg|wav|wma)/\', "", $post->post_content)));
}
}