Inventory_Presser_Customize_Dashboard::enable_order_by_attachment_count( array $pieces, WP_Query $query )

enable_order_by_attachment_count


Description Description

Handle the ORDER BY on the vehicle list (edit.php) when sorting by photo count.


Top ↑

Parameters Parameters

$pieces

(array) (Required)

$query

(WP_Query) (Required)


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class-customize-admin-dashboard.php

	function enable_order_by_attachment_count( $pieces, $query )
	{
		if( ! is_admin() ) { return $pieces; }

		/**
		 * We only want our code to run in the main WP query
		 * AND if an orderby query variable is designated.
		 */
		if ( $query->is_main_query() && ( $orderby = $query->get( 'orderby' ) ) )
		{
			// Get the order query variable - ASC or DESC
			$order = strtoupper( $query->get( 'order' ) );

			// Make sure the order setting qualifies. If not, set default as ASC
			if ( ! in_array( $order, array( 'ASC', 'DESC' ) ) )
			{
				$order = 'ASC';
			}

			if( apply_filters( 'invp_prefix_meta_key', 'photo_count' ) == $orderby
				|| apply_filters( 'invp_prefix_meta_key', 'thumbnail' ) == $orderby )
			{
				global $wpdb;
				$pieces[ 'orderby' ] = "( SELECT COUNT( ID ) FROM {$wpdb->posts} forget WHERE post_parent = {$wpdb->posts}.ID ) $order, " . $pieces[ 'orderby' ];
			}
	   }
	   return $pieces;
	}