wp_post_mime_type_where( string|string[] $post_mime_types, string $table_alias = '' ): string
- Since
- 2.5.0
- Source
wp-includes/post.php:3765
Compatibility
- WordPress
- since 2.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$post_mime_typesstring|string[]- List of mime types or comma separated string of mime types.
$table_aliasstringoptional- Specify a table alias, if needed.
Default empty.Default:''
Return value
string- The SQL AND clause for mime searching.
Performance profile
How much work a call to wp_post_mime_type_where() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 12–51
- Plugin surface
- None
- Called by
- 2
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 95.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_post_mime_type_where() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_string($post_mime_types) | 12–42 | none |
is_string($post_mime_types) | 21–51 | explode(), array_map() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 95 | 12–51 | 11 | |
| 8.5 | 95 | 12–51 | 11 | |
| 8.4 | 95 | 12–51 | 11 | 36 fewer instructions than PHP 8.3 |
| 8.3 | 131 | 12–75 | 11 | |
| 8.2 | 131 | 12–75 | 11 | |
| 8.1 | 131 | 12–75 | 11 | 4 fewer instructions than PHP 7.4 |
| 7.4 | 135 | 12–75 | 11 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 1
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
Used by · 2
- WP_Query::get_posts()Retrieves an array of posts based on query variables.
- wp_count_attachments()Counts number of attachments for the mime type(s).
Source code
function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) { $where = ''; $wildcards = array( '', '%', '%/%' ); if ( is_string( $post_mime_types ) ) { $post_mime_types = array_map( 'trim', explode( ',', $post_mime_types ) ); } $where_clauses = array(); foreach ( (array) $post_mime_types as $mime_type ) { $mime_type = preg_replace( '/\s/', '', $mime_type ); $slashpos = strpos( $mime_type, '/' ); if ( false !== $slashpos ) { $mime_group = preg_replace( '/[^-*.a-zA-Z0-9]/', '', substr( $mime_type, 0, $slashpos ) ); $mime_subgroup = preg_replace( '/[^-*.+a-zA-Z0-9]/', '', substr( $mime_type, $slashpos + 1 ) ); if ( empty( $mime_subgroup ) ) { $mime_subgroup = '*'; } else { $mime_subgroup = str_replace( '/', '', $mime_subgroup ); } $mime_pattern = "$mime_group/$mime_subgroup"; } else { $mime_pattern = preg_replace( '/[^-*.a-zA-Z0-9]/', '', $mime_type ); if ( ! str_contains( $mime_pattern, '*' ) ) { $mime_pattern .= '/*'; } } $mime_pattern = preg_replace( '/\*+/', '%', $mime_pattern ); if ( in_array( $mime_type, $wildcards, true ) ) { return ''; } if ( str_contains( $mime_pattern, '%' ) ) { $where_clauses[] = empty( $table_alias ) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; } else { $where_clauses[] = empty( $table_alias ) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; } } if ( ! empty( $where_clauses ) ) { $where = ' AND (' . implode( ' OR ', $where_clauses ) . ') '; } return $where;}Changelog
Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.