附件本身与帖子相同。。。因此,您可以考虑为tham提供meta\\u值或为tham添加分类法。至于我,我总是用第一种方法。。。这是函数性如何工作的一个简单示例。。。
add_filter("attachment_fields_to_edit", "afields_to_edit", 10, 2);
add_filter("attachment_fields_to_save", "afields_to_save", 10, 2);
function afields_to_save($post, $attachment){
$parentPost = get_post($post[\'post_parent\']);
/*************************************************************
// Roles
*************************************************************/
if (isset($_POST[\'___attachments\'][$post[\'ID\']][\'type\'])
&& trim($_POST[\'___attachments\'][$post[\'ID\']][\'type\']) != ""){
$type = $_POST[\'___attachments\'][$post[\'ID\']][\'type\'];
update_post_meta($post[\'ID\'], \'_type\', $type);
} else {
delete_post_meta($post[\'ID\'], \'_type\');
}
return $post;
}
function afields_to_edit($form_fields, $post){
$parentPost = get_post($post->post_parent);
/***********************************************************************
Roles
***********************************************************************/
$form_fields["roles"]["label"] = "File Role";
$form_fields["roles"]["input"] = "html";
$html .= "<select name=\'___attachments[".$post->ID."][type]\' style=\'width:95%;\'>";
$html .= "<option value=\'\'>Default Role</option>";
$roles = apply_filters(\'roles_sidebar\', array(), $post, $parentPost);
if (is_array($roles) && count($roles) > 0){
foreach($roles as $key=>$role){
$html .= "<option value=\'".$key."\' ".$role[\'select\'].">".$role[\'name\']."</option>";
}
}
$html .= "</select>";
$form_fields["roles"]["html"] = $html;
return $form_fields;
}
我想你可以这样继续工作。。。