define(\'MY_POST_TYPE\', \'myslider\');
define(\'MY_POST_SLUG\', \'myslider\');
function my_register_post_type () {
$args = array (
\'label\' => \'Gallery\',
\'supports\' => array( \'title\', \'excerpt\' ),
\'register_meta_box_cb\' => \'my_meta_box_cb\',
\'show_ui\' => true,
\'orderby\' => \'meta_value_num\',
\'query_var\' => true,
\'order\' => \'ASC\',
\'public\' => true,
\'publicly_queryable\' => false,
\'show_in_menu\' => true,
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => true,
\'menu_position\' => null,
);
register_post_type( MY_POST_TYPE , $args );
}
add_action( \'init\', \'my_register_post_type\' );
function my_meta_box_cb () {
add_meta_box( MY_POST_TYPE . \'_details\' , \'Media Library\', \'my_meta_box_details\', MY_POST_TYPE, \'normal\', \'high\' );
}
function my_meta_box_details () {
global $post;
$post_ID = $post->ID; // global used by get_upload_iframe_src
printf( "<iframe frameborder=\'0\' src=\' %s \' style=\'width: 100%%; height: 400px;\'> </iframe>", get_upload_iframe_src(\'media\') );
}
最合适的回答,由SO网友:Adeel 整理而成
完美工作:)
/////////创建附件自定义字段///////////////////////function be\\u attachment\\u field\\u credit($form\\u fields,$post){$form\\u fields[\'custom6]=数组(\'label\'=>\'custom6 Name\',\'input\'=>\'text\',\'value\'=>get\\u post\\u meta($post->ID,\'custom6\',true),\'help\'=>\'custom6 text\',);
$form_fields[\'custom7\'] = array(
\'label\' => \'Custom7 URL\',
\'input\' => \'text\',
\'value\' => get_post_meta( $post->ID, \'custom7\', true ),
\'helps\' => \'custom7 link\',
);
return $form_fields;
}
添加\\u筛选器(“attachment\\u fields\\u to\\u edit”,“be\\u attachment\\u field\\u credit”,10,2);
/////////附件自定义字段保存//////////////////////
函数be\\u attachment\\u field\\u credit\\u save($post,$attachment){if(isset($attachment[\'custom6]))update\\u post\\u meta($post[\'ID],\'custom6],$attachment[\'custom6]);
if( isset( $attachment[\'custom7\'] ) )
update_post_meta( $post[\'ID\'], \'custom7\', $attachment[\'custom7\'] );
return $post;
}