如何在wordpress中通过分类法连接附件和用户

How to connect attachment and users through taxonomy in wordpress

我想限制相关用户访问附件。因此管理员可以在上传文件后 select 用户将他们与附件相关联。

我的计划是用分类法来做,但是当我这样做的时候:

$attachment_taxonomies[] = array(
                'taxonomy'  => 'attachment_user',
                'post_type' => 'attachment',
                'args'      => $args
            );

该用户不是真正的用户,它只是某种文本。

是否可以用分类法来做,或者有更好的方法吗?

我用 post 元数据而不是分类法解决了它。

// add meta box for attachment
add_action( 'add_meta_boxes', array( $this, 'add_user_meta_box' ) );

// save data from meta box
add_action( 'edit_attachment', array( $this, 'save_user_meta_box'), 10, 3 );

// Add the custom columns to the media post type:
add_filter( 'manage_media_columns', array( $this, 'set_custom_user_column' ) );

// Add the data to the custom columns for the media post type:
add_action( 'manage_media_custom_column' , array( $this, 'custom_attachment_column' ), 10, 2 );

要获取用户下拉菜单,您可以使用 wp_dropdown_users