Reply To: Custom Query – how to use / to show different order? | WP Masonry Layout

Reply To: Custom Query – how to use / to show different order?

Home Forums Pro Version Custom Query – how to use / to show different order? Reply To: Custom Query – how to use / to show different order?

#6412
snikay
Participant

Hm, if i just paste this into the custom query field, the order still is by date/last posts.

This is the code I had to put into the functions.php:

//code for changing the custom post order
function wpeddit_order($query) {
		global $wp_query;
		if ( ! $query->is_main_query() )
	    return $query;
		
	      if(!is_page() || !is_admin()){
	      	if(is_main_query()){
				$query->set('meta_key', 'epicredrank');
		  		$query->set('orderby', 'meta_value_num');
		  		$query->set('order', 'DESC');
			}
	      }
		return $query;
}
add_action('pre_get_posts','wpeddit_order');