Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Last active October 10, 2018 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgibbs189/5d40db9ebc8b629916cc1a816f48a222 to your computer and use it in GitHub Desktop.
Save mgibbs189/5d40db9ebc8b629916cc1a816f48a222 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'facetwp_sort_options', function( $options, $params ) {
$options['on_sale'] = array(
'label' => 'On Sale',
'query_args' => array(
'sort_on_sale' => true,
'meta_query' => array(
array(
'key' => '_tilbud' // on sale
),
array(
'key' => '_nypris' // price
)
)
)
);
$options['price_asc'] = array(
'label' => 'Price (lowest)',
'query_args' => array(
'meta_key' => '_nypris',
'orderby' => 'meta_value_num',
'order' => 'ASC'
)
);
return $options;
}, 10, 2 );
// Sort by on sale (_tilbud), then by price (_nypris) ASC
add_filter( 'posts_orderby', function( $orderby, $wp_query ) {
if ( isset( $wp_query->query_vars['sort_on_sale'] ) ) {
$orderby = 'mt1.meta_value ASC, mt2.meta_value+0 ASC';
}
return $orderby;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment