Tribe__Events__Aggregator__Records::count_by_origin( array $type = array('schedule', 'manual'), string|array $raw_statuses = '' )
Count the number of imports based on origin.
Contents
Parameters
- $type
-
(<span class="array">array) (Optional) The type of import.
Default value: array('schedule', 'manual')
- $raw_statuses
-
(string|array) (Optional) The statuses of the imports to look in.
Default value: ''
Return
(array)
Source
File: src/Tribe/Aggregator/Records.php
public function count_by_origin( $type = array( 'schedule', 'manual' ), $raw_statuses = '' ) {
global $wpdb;
$where = array(
'post_type = %s',
'AND post_status NOT IN ( \'' . self::$status->draft . '\' )',
);
$statuses = array();
// Make it an Array
$raw_statuses = (array) $raw_statuses;
foreach ( $raw_statuses as $status ) {
if ( ! isset( self::$status->{ $status } ) ) {
continue;
}
// Get the Actual Status for the Database
$statuses[] = self::$status->{ $status };
}
if ( ! empty( $type ) ) {
$where[] = 'AND ping_status IN ( \'' . implode( '\', \'', (array) $type ) . '\' )';
}
if ( ! empty( $statuses ) ) {
$where[] = 'AND post_status IN ( \'' . implode( '\', \'', $statuses ) . '\' )';
}
$where = implode( ' ', $where );
$sql = $wpdb->prepare( "SELECT post_mime_type as origin, COUNT(*) as count
FROM $wpdb->posts
WHERE {$where}
GROUP BY origin;", self::$post_type );
$results = $wpdb->get_results( $sql );
// Prevents Warnings With `array_combine`
if ( empty( $results ) ) {
return array();
}
$origins = wp_list_pluck( $results, 'origin' );
$counts = wp_list_pluck( $results, 'count' );
// Remove ea/ from the `post_mime_type`
foreach ( $origins as &$origin ) {
$origin = str_replace( 'ea/', '', $origin );
}
return array_combine( $origins, $counts );
}
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |