wp_count_attachments [ WordPress Function ]
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Count number of attachments for the mime type(s).
If you set the optional mime_type parameter, then an array will still be returned, but will only have the item you are looking for. It does not give you the number of attachments that are children of a post. You can get that by counting the number of children that post has.
Source
<?php
function wp_count_attachments( $mime_type = '' ) {
global $wpdb;
$and = wp_post_mime_type_where( $mime_type );
$count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A );
$stats = array( );
foreach( (array) $count as $row ) {
$stats[$row['post_mime_type']] = $row['num_posts'];
}
$stats['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and");
return (object) $stats;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- wp_count_attachments (WordPress Function) - WPSeek.com
WordPress lookup for wp_count_attachments, a WordPress Function. wpseek. com is a WordPress-centric search tool for developers and theme authors.
wpseek.com - wp_count_attachments
Function and Method Cross Reference. wp_count_attachments(). Defined at: /wp -includes/post.php -> line 1891. Referenced 2 times: ...
phpxref.ftwr.co.uk - #17071 (wp_count_attachments() is not filterable) – WordPress Trac
The Media Library attachments listing and edit links can be filtered via existing WP_Query and has_cap hooks. However, corresponding attachment counts are ...
core.trac.wordpress.org - Docs for page post.php
wp_count_attachments (line 1904). Count number of attachments for the mime type(s). If you set the optional mime_type parameter, then an array will still be ...
phpdoc.wordpress.org