Last active
August 29, 2015 14:25
-
-
Save jainnidhi/757b859a0d7ddef389c0 to your computer and use it in GitHub Desktop.
custom meta query sorting
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
add_filter( 'pre_get_posts', 'sort_by_likes' ); | |
function sort_by_likes( $query ) { | |
if ($query->is_home() && $query->is_main_query() ) { | |
$query->set( 'meta_query', array(array( | |
'key' => '_recommended' | |
))); | |
$query->set('meta_key', '_recommended'); | |
$query->set('orderby', 'meta_value_num'); | |
$query->set('order', 'DESC'); | |
}} | |
OR | |
$query->set('meta_query', array( | |
array( | |
'key' => '_ai_price_int', | |
'value' => array(0, 4000), | |
'compare' => 'BETWEEN', | |
'type' => 'NUMERIC' | |
) | |
)); | |
$query->set('meta_key', '_ai_price_int'); | |
$query->set('orderby', 'meta_value_num'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment