wp_edit_attachments_query()
云策文档标注
概述
wp_edit_attachments_query() 函数用于执行附件查询,并返回 MIME 类型数组。它接受可选的 WP_Query 参数数组来覆盖默认设置。
关键要点
- 函数执行附件查询,基于 wp_edit_attachments_query_vars() 设置查询变量。
- 参数 $q 可选,为数组或 false,用于覆盖默认查询参数,默认使用 $_GET 超全局变量。
- 返回数组包含 post_mime_types 和 avail_post_mime_types,分别表示 MIME 类型和可用 MIME 类型。
- 内部调用 wp()、get_post_mime_types() 和 get_available_post_mime_types() 函数。
- 主要用于媒体库相关功能,如 media_upload_library_form() 和 WP_Media_List_Table::prepare_items()。
代码示例
function wp_edit_attachments_query( $q = false ) {
wp( wp_edit_attachments_query_vars( $q ) );
$post_mime_types = get_post_mime_types();
$avail_post_mime_types = get_available_post_mime_types( 'attachment' );
return array( $post_mime_types, $avail_post_mime_types );
}
原文内容
Executes a query for attachments. An array of WP_Query arguments can be passed in, which will override the arguments set by this function.
Parameters
$qarray|falseoptional-
Array of query variables to use to build the query.
Defaults to the$_GETsuperglobal.Default:
false
Source
function wp_edit_attachments_query( $q = false ) {
wp( wp_edit_attachments_query_vars( $q ) );
$post_mime_types = get_post_mime_types();
$avail_post_mime_types = get_available_post_mime_types( 'attachment' );
return array( $post_mime_types, $avail_post_mime_types );
}
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |