wp_edit_attachments_query_vars

Get the query variables for the current attachments request.

Description

(array) wp_edit_attachments_query_vars( (bool) $q = false ); 

Returns (array)

The parsed query vars.

Parameters (1)

0. $q — Optional. (bool) => false
Array of query variables to use to build the query or false to use $_GET superglobal. Default false.

Usage

  1. if ( !function_exists( 'wp_edit_attachments_query_vars' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/post.php'; 
  3.  
  4. // Optional. Array of query variables to use to build the query or false 
  5. // to use $_GET superglobal. Default false. 
  6. $q = false; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = wp_edit_attachments_query_vars($q); 
  10.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/post.php  
  1. function wp_edit_attachments_query_vars( $q = false ) { 
  2. if ( false === $q ) { 
  3. $q = $_GET; 
  4. $q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0; 
  5. $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; 
  6. $q['post_type'] = 'attachment'; 
  7. $post_type = get_post_type_object( 'attachment' ); 
  8. $states = 'inherit'; 
  9. if ( current_user_can( $post_type->cap->read_private_posts ) ) { 
  10. $states .= ', private'; 
  11.  
  12. $q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : $states; 
  13. $q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' == $q['attachment-filter'] ? 'trash' : $states; 
  14.  
  15. $media_per_page = (int) get_user_option( 'upload_per_page' ); 
  16. if ( empty( $media_per_page ) || $media_per_page < 1 ) { 
  17. $media_per_page = 20; 
  18.  
  19. /** 
  20. * Filters the number of items to list per page when listing media items. 
  21. * @since 2.9.0 
  22. * @param int $media_per_page Number of media to list. Default 20. 
  23. */ 
  24. $q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page ); 
  25.  
  26. $post_mime_types = get_post_mime_types(); 
  27. if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) ) { 
  28. unset($q['post_mime_type']); 
  29.  
  30. foreach ( array_keys( $post_mime_types ) as $type ) { 
  31. if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" == $q['attachment-filter'] ) { 
  32. $q['post_mime_type'] = $type; 
  33. break; 
  34.  
  35. if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' == $q['attachment-filter'] ) ) { 
  36. $q['post_parent'] = 0; 
  37.  
  38. // Filter query clauses to include filenames. 
  39. if ( isset( $q['s'] ) ) { 
  40.  
  41. return $q;