你需要做的是运行一个函数,当点击帖子上的“更新”按钮时会触发该函数。
我不能保证我隔离短代码的尝试是成功的,(我不太擅长这方面),但你肯定明白了!
add_action(\'save_post\', \'save_details\');
function save_details() {
global $post;
if(get_post_type($post->ID) == \'your_custom_post_type\') {
if(stripos($post->post_content, \'[audio:http://\') !== false) { // if shortcode exists
$content = $post->post_content;
//first position of shortcode
$p1 = stripos($content, \'[audio:http://\');
// strip code from before the shortcode.
$content = substr($content, $p1);
//find when end of the shortcode starts
$p2 = stripos($content, \'.mp3]\');
$p2 = $p2 + 5; // add five to get where it ends.
//get full shortcode
$content = substr($content, 0, $p2);
// save shortcode to meta field
update_post_meta($post->ID, \'custom_field_name\', $content);
}
}
}
如果你有任何麻烦,请告诉我!