Created
April 8, 2017 07:43
-
-
Save infoscigeek/95bddb6e97a2ee8aa841fa52ee1ade2b to your computer and use it in GitHub Desktop.
Order an archive page for a post category by a numeric custom field
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 | |
/*Custom sort cateogry id 5 archive */ | |
function isg_custom_property_archive( $query ) { | |
// only modify queries for category 5 if it exists | |
if ( !is_admin() && term_exists(5,'category') && $query->is_category(5)) { | |
$query->set('posts_per_page','-1'); | |
$query->set('offset','0'); | |
$query->set('orderby', 'meta_value_num'); | |
$query->set('meta_key', 'price'); | |
$query->set('order', 'DESC'); | |
} | |
} | |
add_filter( 'pre_get_posts', 'isg_custom_property_archive' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment