在底部链接的Trac记录单上,有一个解决方案可以使其正常工作
function _save_attachment_url($post, $attachment) {
if ( isset($attachment[\'url\']) )
update_post_meta( $post[\'ID\'], \'_wp_attachment_url\', esc_url_raw($attachment[\'url\']) );
return $post;
}
add_filter(\'attachment_fields_to_save\', \'_save_attachment_url\', 10, 2);
function _replace_attachment_url($form_fields, $post) {
if ( isset($form_fields[\'url\'][\'html\']) ) {
$url = get_post_meta( $post->ID, \'_wp_attachment_url\', true );
if ( ! empty($url) )
$form_fields[\'url\'][\'html\'] = preg_replace( "/value=\'.*?\'/", "value=\'$url\'", $form_fields[\'url\'][\'html\'] );
}
return $form_fields;
}
add_filter(\'attachment_fields_to_edit\', \'_replace_attachment_url\', 10, 2);
因此,在此代码之后,您将能够在“链接URL”字段中添加自定义链接。
要获取它,您只需要附件ID,您可以通过以下方式获取:
get_post_meta( $post->ID, \'_wp_attachment_url\', true );