src/class-extended-cpt.php
public static function get_sort_field_vars( array $vars, array $sortables ) : array {

		if ( ! isset( $vars['orderby'] ) ) {
			return [];
		}
		if ( ! is_string( $vars['orderby'] ) ) {
			return [];
		}
		if ( ! isset( $sortables[ $vars['orderby'] ] ) ) {
			return [];
		}

		$orderby = $sortables[ $vars['orderby'] ];

		if ( ! is_array( $orderby ) ) {
			return [];
		}
		if ( isset( $orderby['sortable'] ) && ! $orderby['sortable'] ) {
			return [];
		}

		$return = [];

		if ( isset( $orderby['meta_key'] ) ) {
			$return['meta_key'] = $orderby['meta_key'];
			$return['orderby']  = 'meta_value';
			// @TODO meta_value_num
		} elseif ( isset( $orderby['post_field'] ) ) {
			$field = str_replace( 'post_', '', $orderby['post_field'] );
			$return['orderby'] = $field;
		}

		if ( isset( $vars['order'] ) ) {
			$return['order'] = $vars['order'];
		}

		return $return;

	}
public static function get_sort_field_vars( array $vars, array $sortables ) : array {

		if ( ! isset( $vars['orderby'] ) ) {
			return [];
		}
		if ( ! is_string( $vars['orderby'] ) ) {
			return [];
		}
		if ( ! isset( $sortables[ $vars['orderby'] ] ) ) {
			return [];
		}

		$orderby = $sortables[ $vars['orderby'] ];

		if ( ! is_array( $orderby ) ) {
			return [];
		}
		if ( isset( $orderby['sortable'] ) && ! $orderby['sortable'] ) {
			return [];
		}

		$return = [];

		if ( isset( $orderby['meta_key'] ) ) {
			$return['meta_key'] = $orderby['meta_key'];
			$return['orderby']  = 'meta_value';
			// @TODO meta_value_num
		} elseif ( isset( $orderby['post_field'] ) ) {
			$field = str_replace( 'post_', '', $orderby['post_field'] );
			$return['orderby'] = $field;
		}

		if ( isset( $vars['order'] ) ) {
			$return['order'] = $vars['order'];
		}

		return $return;

	}
public static function get_sort_field_vars ( array $ vars , array $ sortables ) : array { if ( ! isset ( $ vars [ 'orderby' ] ) ) { return [ ] ; } if ( ! is_string ( $ vars [ 'orderby' ] ) ) { return [ ] ; } if ( ! isset ( $ sortables [ $ vars [ 'orderby' ] ] ) ) { return [ ] ; } $ orderby = $ sortables [ $ vars [ 'orderby' ] ] ; if ( ! is_array ( $ orderby ) ) { return [ ] ; } if ( isset ( $ orderby [ 'sortable' ] ) && ! $ orderby [ 'sortable' ] ) { return [ ] ; } $ return = [ ] ; if ( isset ( $ orderby [ 'meta_key' ] ) ) { $ return [ 'meta_key' ] = $ orderby [ 'meta_key' ] ; $ return [ 'orderby' ] = 'meta_value' ; // @TODO meta_value_num } elseif ( isset ( $ orderby [ 'post_field' ] ) ) { $ field = str_replace ( 'post_' , '' , $ orderby [ 'post_field' ] ) ; $ return [ 'orderby' ] = $ field ; } if ( isset ( $ vars [ 'order' ] ) ) { $ return [ 'order' ] = $ vars [ 'order' ] ; } return $ return ; }
Get the array of private and public query vars for the given sortables, to apply to the current query in order to
sort it by the requested orderby field.

@param  array $vars      The public query vars, usually from `$wp_query->query`.
@param  array $sortables The sortables valid for this query (usually the value of the `admin_cols` or
`site_sortables` argument when registering an extended post type.
@return array            The list of private and public query vars to apply to the query.
Get the array of private and public query vars for the given sortables to apply to the current query in order to sort it by the requested orderby field .