- This topic has 12 replies, 2 voices, and was last updated 8 years, 3 months ago by .
These forums are now closed and remain for historical purposes.
None of the content applies to the new version 3. For support, get in touch via our contact form.
Forums › Forums › Search & Filter Pro › ordering by meta key is not working
Tagged: ordering
You have an error in your plugin. I did some debugging and I figured out that WP_Query’s orderby and meta_key values are not properly set. This code fixed my problem.
function czus_fix_wrong_filter_orderby( $query ) {
if(!is_admin() && is_main_query() && $query->query[‘search_filter_id’] === 95) {
$query->set( ‘meta_key’, ‘last_update’ );
$query->set( ‘orderby’, ‘meta_value_num’ );
}
}
add_action( ‘pre_get_posts’, ‘czus_fix_wrong_filter_orderby’ );