Last active
October 10, 2018 18:30
-
-
Save mgibbs189/5d40db9ebc8b629916cc1a816f48a222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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