Tag Info

Hot answers tagged

3

You can pass a space-delimited set of columns to orderby argument of WP Query: $args = array( 'meta_key' => 'wp_ratings', 'orderby' => 'meta_value_num date' ); $query = new WP_Query( $args ); You can also pass an array of key => sort_order for more granular control, for example: $args = array( 'meta_key' => 'wp_ratings', ...


1

This is untested, but I believe if you set type in your meta query to numeric, that will cast the values as numbers so orderby meta_value should work correctly.


1

You're not using query_vars quite right - this filter is for whitelisting "public" query vars, not actually setting their values. It's also called rather early (wp::parse_request), so any conditional tags like is_tax() will always be false at this stage. Use the pre_get_posts action for overriding the default query. Having said that, you need a custom ORDER ...


1

You want to orderby 'date' not by 'meta_value_num' because it is to order numerically. So if you were ordering items by their price, then you would want to use 'meta_value_num'. The meta_key 'news_date' is most likely in date format. You should also cast the meta_value to DATE using 'meta_type' => 'DATE'. $args = array( 'post_type' => 'news', ...



Only top voted, non community-wiki answers of a minimum length are eligible