Title: wp_edit_attachments_query_vars
Published: April 23, 2015
Last modified: August 20, 2026

---

# wp_edit_attachments_query_vars( array|false $q = false ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#wp--skip-link--target)

Returns the query variables for the current attachments request.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#parameters)󠁿

 `$q`array|falseoptional

Array of query variables to use to build the query.
 Defaults to the `$_GET` superglobal.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#return)󠁿

 array The parsed query vars.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#source)󠁿

    ```php
    function wp_edit_attachments_query_vars( $q = false ) {
    	if ( false === $q ) {
    		$q = $_GET;
    	}
    	$q['m']         = isset( $q['m'] ) ? (int) $q['m'] : 0;
    	$q['cat']       = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
    	$q['post_type'] = 'attachment';
    	$post_type      = get_post_type_object( 'attachment' );
    	$states         = 'inherit';
    	if ( current_user_can( $post_type->cap->read_private_posts ) ) {
    		$states .= ',private';
    	}

    	$q['post_status'] = isset( $q['status'] ) && 'trash' === $q['status'] ? 'trash' : $states;
    	$q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' === $q['attachment-filter'] ? 'trash' : $states;

    	$media_per_page = (int) get_user_option( 'upload_per_page' );
    	if ( empty( $media_per_page ) || $media_per_page < 1 ) {
    		$media_per_page = 20;
    	}

    	/**
    	 * Filters the number of items to list per page when listing media items.
    	 *
    	 * @since 2.9.0
    	 *
    	 * @param int $media_per_page Number of media to list. Default 20.
    	 */
    	$q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page );

    	$post_mime_types = get_post_mime_types();
    	if ( isset( $q['post_mime_type'] ) && ! array_intersect( (array) $q['post_mime_type'], array_keys( $post_mime_types ) ) ) {
    		unset( $q['post_mime_type'] );
    	}

    	foreach ( array_keys( $post_mime_types ) as $type ) {
    		if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" === $q['attachment-filter'] ) {
    			$q['post_mime_type'] = $type;
    			break;
    		}
    	}

    	if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' === $q['attachment-filter'] ) ) {
    		$q['post_parent'] = 0;
    	}

    	if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' === $q['attachment-filter'] ) ) {
    		$q['author'] = get_current_user_id();
    	}

    	// Filter query clauses to include filenames.
    	if ( isset( $q['s'] ) ) {
    		add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
    	}

    	return $q;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-admin/includes/post.php#L1329)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-admin/includes/post.php#L1329-L1385)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#hooks)󠁿

 [apply_filters( ‘upload_per_page’, int $media_per_page )](https://developer.wordpress.org/reference/hooks/upload_per_page/)

Filters the number of items to list per page when listing media items.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#related)󠁿

| Uses | Description | 
| [get_user_option()](https://developer.wordpress.org/reference/functions/get_user_option/)`wp-includes/user.php` |

Retrieves user option that can be either per Site or per Network.

  | 
| [get_post_mime_types()](https://developer.wordpress.org/reference/functions/get_post_mime_types/)`wp-includes/post.php` |

Gets default post mime types.

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [add_filter()](https://developer.wordpress.org/reference/functions/add_filter/)`wp-includes/plugin.php` |

Adds a callback function to a filter hook.

  | 
| [get_current_user_id()](https://developer.wordpress.org/reference/functions/get_current_user_id/)`wp-includes/user.php` |

Gets the current user’s ID.

  | 
| [get_post_type_object()](https://developer.wordpress.org/reference/functions/get_post_type_object/)`wp-includes/post.php` |

Retrieves a post type object by name.

  |

[Show 5 more](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#)

| Used by | Description | 
| [wp_edit_attachments_query()](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query/)`wp-admin/includes/post.php` |

Executes a query for attachments. An array of [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/) arguments can be passed in, which will override the arguments set by this function.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_edit_attachments_query_vars/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_edit_attachments_query_vars%2F)
before being able to contribute a note or feedback.