epl_get_sorter_query_args(): WP_Query sort arguments for a sort option
Description #
Turns a sort option from epl_sorting_options() into WP_Query arguments (order, orderby and, for meta sorts, meta_key), with tiebreakers so listings with the same value always come back in the same order. EPL uses it when visitors sort listings. Use it to sort your own listing query the same way.
Usage #
$args = epl_get_sorter_query_args( $sorter );
Parameters #
$sorter (array)
A sort option:
type:metato sort by a listing field,postto sort by a post field.key: the meta key (meta sorts) or post field such aspost_dateorpost_title(post sorts).order:ASCorDESC. Anything other than ASC is treated as DESC.orderby: meta sorts only,meta_value(text) ormeta_value_num(numbers). Defaultmeta_value.
id and label are ignored here.
Return #
An array of WP_Query arguments: order, orderby (orderby => order pairs, primary sort first, filtered by epl_sorter_orderby) and meta_key for meta sorts. Random sorts, none, and an orderby that already lists several keys are returned as they are, as a string.
Examples #
A custom loop of properties sorted like the Price: Low to High option:
$sorter = wp_list_filter( epl_sorting_options( 'property' ), array( 'id' => 'low' ) ); $args = array_merge( array( 'post_type' => 'property', 'posts_per_page' => 12, 'paged' => max( 1, get_query_var( 'paged' ) ), ), epl_get_sorter_query_args( current( $sorter ) ) ); $listings = new WP_Query( $args ); // $args now includes: // 'order' => 'ASC', // 'meta_key' => 'property_price_global', // 'orderby' => array( 'meta_value_num' => 'ASC', 'date' => 'DESC', 'ID' => 'DESC' ),
With your own sort option:
$args = epl_get_sorter_query_args( array( 'type' => 'meta', 'key' => 'property_bedrooms', 'order' => 'DESC', 'orderby' => 'meta_value_num', ) );
Source #
lib/includes/template-functions.php, in epl_get_sorter_query_args(). Used by epl_archive_sorting() and epl_add_orderby_args(). Since 3.6.