Skip to content

Instantly share code, notes, and snippets.

@gspice
Last active July 17, 2017 18:29
Show Gist options
  • Select an option

  • Save gspice/d3b4741ba40bdf0a4fdf to your computer and use it in GitHub Desktop.

Select an option

Save gspice/d3b4741ba40bdf0a4fdf to your computer and use it in GitHub Desktop.
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
}
}
@jamiewhiteVA
Copy link
Copy Markdown

This succeeded in sorting my listings by price, but it removed the listings' thumbnail images from the homepage. Has anyone else experienced this issue, and is there a known solution at this time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment