如何创建更多的“创建附件”自定义域-有什么想法吗?

时间:2013-09-26 作者:Adeel
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\') );
  }
2 个回复
最合适的回答,由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;
}

SO网友:Chief Alchemist

我不太确定我是否理解你的问题,但如果让我猜一下,这可能会有所帮助:

add_meta_box() Examples - WordPress Codex

结束