Support

Account

Home Forums General Issues Sorting by custom fields Reply To: Sorting by custom fields

  • Thanks for your response.
    Here is the filter I am using, (I am using it with WooCommerce products) and I am not using type of ‘DATE’ (although I did try when I couldn’t get the following to work)

    	$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    	switch( $orderby_value ) {
    	
    		case 'release_date':
    			$sort_args['orderby']  = 'meta_value';
    			$sort_args['order']    = 'desc';
    			$sort_args['meta_key'] = 'release_date';
    			break;
    		
    	}
    	
    	return $sort_args;