| | 1013 | * Allow 'meta_query' to persist during wp() |
| | 1014 | * |
| | 1015 | * @since 4.0.0 |
| | 1016 | * |
| | 1017 | * @param array $q Query vars constructed during WP->parse_request() |
| | 1018 | * @return array The altered query vars. |
| | 1019 | */ |
| | 1020 | function _wp_filter_attachment_search( $q ) { |
| | 1021 | remove_filter( 'request', __FUNCTION__ ); |
| | 1022 | |
| | 1023 | $q['meta_query'] = array( |
| | 1024 | 'relation' => 'OR', |
| | 1025 | array( |
| | 1026 | 'key' => '_wp_attached_file', |
| | 1027 | 'value' => $q['s'], |
| | 1028 | 'compare' => 'LIKE' |
| | 1029 | ) |
| | 1030 | ); |
| | 1031 | return $q; |
| | 1032 | } |
| | 1033 | |
| | 1034 | /** |
| | 1035 | * Filter meta SQL to mark this search criteria as optional |
| | 1036 | * |
| | 1037 | * @since 4.0.0 |
| | 1038 | * |
| | 1039 | * @param array $sql 'where' and 'join' clauses. |
| | 1040 | * @return array The filtered clauses. |
| | 1041 | */ |
| | 1042 | function _wp_filter_attachment_meta_sql( $sql ) { |
| | 1043 | remove_filter( 'get_meta_sql', __FUNCTION__ ); |
| | 1044 | if ( 0 === strpos( $sql['where'], ' AND (' ) ) { |
| | 1045 | list( $_, $clauses ) = explode( ' AND ', $sql['where'], 2 ); |
| | 1046 | $sql['where'] = " OR ({$clauses})"; |
| | 1047 | } |
| | 1048 | return $sql; |
| | 1049 | } |
| | 1050 | |
| | 1051 | /** |