wp_post_mime_type_where example

if ( ! in_array( $q['comment_count']['compare']$compare_operators, true ) ) {
                    $q['comment_count']['compare'] = '=';
                }

                $where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_count {$q['comment_count']['compare']} %d", $q['comment_count']['value'] );
            }
        }

        // MIME-Type stuff for attachment browsing.
        if ( isset( $q['post_mime_type'] ) && '' !== $q['post_mime_type'] ) {
            $whichmimetype = wp_post_mime_type_where( $q['post_mime_type']$wpdb->posts );
        }
        $where .= $search . $whichauthor . $whichmimetype;

        if ( ! empty( $this->allow_query_attachment_by_filename ) ) {
            $join .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
        }

        if ( ! empty( $this->meta_query->queries ) ) {
            $clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this );
            $join   .= $clauses['join'];
            $where  .= $clauses['where'];
        }

function wp_count_attachments( $mime_type = '' ) {
    global $wpdb;

    $cache_key = sprintf(
        'attachments%s',
        ! empty( $mime_type ) ? ':' . str_replace( '/', '_', implode( '-', (array) $mime_type ) ) : ''
    );

    $counts = wp_cache_get( $cache_key, 'counts' );
    if ( false == $counts ) {
        $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 );

        $counts = array();
        foreach ( (array) $count as $row ) {
            $counts[ $row['post_mime_type'] ] = $row['num_posts'];
        }
        $counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and);

        wp_cache_set( $cache_key(object) $counts, 'counts' );
    }

    
Home | Imprint | This part of the site doesn't use cookies.