_filter_query_attachment_filenames

Filter the SQL clauses of an attachment query to include filenames.

Description

(array) _filter_query_attachment_filenames( (array) $clauses ); 

Returns (array)

The modified clauses.

Parameters (1)

0. $clauses (array)
An array including WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT, fields (SELECT), and LIMITS clauses.

Usage

  1. if ( !function_exists( '_filter_query_attachment_filenames' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // An array including WHERE, GROUP BY, JOIN, ORDER BY, 
  5. // DISTINCT, fields (SELECT), and LIMITS clauses. 
  6. $clauses = array(); 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = _filter_query_attachment_filenames($clauses); 
  10.  

Defined (1)

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

/wp-includes/post.php  
  1. function _filter_query_attachment_filenames( $clauses ) { 
  2. global $wpdb; 
  3. remove_filter( 'posts_clauses', __FUNCTION__ ); 
  4.  
  5. // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs. 
  6. $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )"; 
  7.  
  8. $clauses['groupby'] = "{$wpdb->posts}.ID"; 
  9.  
  10. $clauses['where'] = preg_replace( 
  11. "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",  
  12. "$0 OR ( sq1.meta_value $1 $2 )",  
  13. $clauses['where'] ); 
  14.  
  15. return $clauses;