先在你的插件parts目录下创建一个media目录,然后新建一个demo-media.php文件,然后跟其他settings时建控件方法一样:代码如下
<?php /* Title: My Media MetaBox Capability: manage_options */ piklist('field', array( 'type' => 'text' ,'scope' => 'post_meta' ,'field' => 'field_name' ,'label' => 'Example Field' ,'description' => 'Field Description' )); piklist('field', array( 'type' => 'colorpicker' ,'scope' => 'post_meta' ,'field' => 'colorpicker_name' ,'label' => 'ColorPicker Field' ,'description' => 'Color Description' ));
注意,因为media有点特殊,它的metabox 是在你edit时才会显示出来,另外还有现在的piklist 0.7.2版本显示注释属性Title位置错了,论坛已经有人反应,预计下一版本会修正。如下图:
前台取该metabox值:
$args = array( 'post_type' => 'attachment','post_status' => 'inherit'); $query = new WP_Query($args); $query2 = get_posts($args); $query3 = query_posts($args); var_dump($wp_query->post); echo get_post_meta($query2[1]->ID, 'field_name', true);
注意:三种取值方式中,因为attachment的特殊性,WP_Query和query_posts都要加上post_status才会查询到正确结果,因为是二次编辑所以post_status参数为inherit,而get_posts可以就一个post_type参数就能查出attachment的内容
发表评论
要发表评论,您必须先登录。