Reply To: Different "Order By" Sorting

Home Forums Pro Version Different "Order By" Sorting Reply To: Different "Order By" Sorting

#5655
snikay
Participant

If i set “Order By default” it just does nothing and keeps listing the posts by date (new-to-old) – WP default. If i select “Order by none” it’s date backwards (old-to-new).

This is the code i put in my functions.php to get the WPeddit order to show up:

//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');