Skip to content

Instantly share code, notes, and snippets.

@gspice
gspice / APL-sort-listings-by-price.php
Last active July 17, 2017 18:29
Finally solved! Code to sort AgentPress Listings by price. Thanks to Carrie Dils showing the thread in github for this -- update was suggested by Andrew Norcross that was added to the plugin code. A sortable column was added called listing_price_sortable. This allowed only the numeric value of the price to be stored separately and updated each t…
//change sort order to price high to low
add_action( 'pre_get_posts', 'gsc_listing_price_sort_order' );
function gsc_listing_price_sort_order( $query ) {
if( !is_admin() && is_post_type_archive( 'listing' ) ) {
$query->set( 'meta_key', '_listing_price_sortable' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'desc' ); //list high to low