src/class-extended-cpt.php
public function maybe_sort_by_fields( WP_Query $wp_query ) {

		if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->post_type, (array) $wp_query->query['post_type'], true ) ) {
			return;
		}

		// If we've not specified an order:
		if ( empty( $wp_query->query['orderby'] ) ) {

			// Loop over our sortables to find the default sort field (if there is one):
			foreach ( $this->args['site_sortables'] as $id => $col ) {
				if ( is_array( $col ) && isset( $col['default'] ) ) {
					// @TODO Don't set 'order' if 'orderby' is an array (WP 4.0+)
					$wp_query->query['orderby'] = $id;
					$wp_query->query['order']   = ( 'desc' === strtolower( $col['default'] ) ? 'desc' : 'asc' );
					break;
				}
			}
		}

		$sort = self::get_sort_field_vars( $wp_query->query, $this->args['site_sortables'] );

		if ( empty( $sort ) ) {
			return;
		}

		foreach ( $sort as $key => $value ) {
			$wp_query->set( $key, $value );
		}

	}
public function maybe_sort_by_fields( WP_Query $wp_query ) {

		if ( empty( $wp_query->query['post_type'] ) || ! in_array( $this->post_type, (array) $wp_query->query['post_type'], true ) ) {
			return;
		}

		// If we've not specified an order:
		if ( empty( $wp_query->query['orderby'] ) ) {

			// Loop over our sortables to find the default sort field (if there is one):
			foreach ( $this->args['site_sortables'] as $id => $col ) {
				if ( is_array( $col ) && isset( $col['default'] ) ) {
					// @TODO Don't set 'order' if 'orderby' is an array (WP 4.0+)
					$wp_query->query['orderby'] = $id;
					$wp_query->query['order']   = ( 'desc' === strtolower( $col['default'] ) ? 'desc' : 'asc' );
					break;
				}
			}
		}

		$sort = self::get_sort_field_vars( $wp_query->query, $this->args['site_sortables'] );

		if ( empty( $sort ) ) {
			return;
		}

		foreach ( $sort as $key => $value ) {
			$wp_query->set( $key, $value );
		}

	}
public function maybe_sort_by_fields ( WP_Query $ wp_query ) { if ( empty ( $ wp_query -> query [ 'post_type' ] ) || ! in_array ( $ this -> post_type , ( array ) $ wp_query -> query [ 'post_type' ] , true ) ) { return ; } // If we've not specified an order: if ( empty ( $ wp_query -> query [ 'orderby' ] ) ) { // Loop over our sortables to find the default sort field (if there is one): foreach ( $ this -> args [ 'site_sortables' ] as $ id => $ col ) { if ( is_array ( $ col ) && isset ( $ col [ 'default' ] ) ) { // @TODO Don't set 'order' if 'orderby' is an array (WP 4.0+) $ wp_query -> query [ 'orderby' ] = $ id ; $ wp_query -> query [ 'order' ] = ( 'desc' === strtolower ( $ col [ 'default' ] ) ? 'desc' : 'asc' ) ; break ; } } } $ sort = self :: get_sort_field_vars ( $ wp_query -> query , $ this -> args [ 'site_sortables' ] ) ; if ( empty ( $ sort ) ) { return ; } foreach ( $ sort as $ key => $ value ) { $ wp_query -> set ( $ key , $ value ) ; } }
Set the relevant query vars for sorting posts by our front-end sortables.

@param WP_Query $wp_query The current WP_Query object.
Set the relevant query vars for sorting posts by our front - end sortables .