• Just posting this for anyone trying to get this working with the newest version of Gravity Forms. The SQL queries are using outdated table names and need to be updated.
    Replace the static functions in gf_field_sum.php at about line 115 with the following:

    	public static function get_field_values_sum($form_id, $input_id) {
    		global $wpdb;
    
    		$query = apply_filters('gwlimitbysum_query', array(
    				'select' => 'SELECT sum(meta_value)',
    				'from' => "FROM {$wpdb->prefix}gf_entry_meta ld",
    				'where' => $wpdb->prepare("WHERE ld.form_id = %d AND CAST(ld.meta_key as unsigned) = %d", $form_id, $input_id)
    			));
    
    		// Count only entries that are active and not in the trash
    		$query['from'] .= " INNER JOIN {$wpdb->prefix}gf_entry l ON l.id = ld.entry_id";
    		$query['where'] .= " AND l.status = 'active' AND meta_value REGEXP '^-?[0-9]+$'";
    		$sql = implode(' ', $query);
    
    		return $wpdb->get_var($sql);
    	}
    
    	public static function limit_by_approved_only($query) {
    		global $wpdb;
    		$query['from'] .= " INNER JOIN {$wpdb->prefix}gf_entry l ON l.id = ld.entry_id";
    		$query['where'] .= ' AND l.payment_status = \'Paid\'';
    		return $query;
    	}
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Here is a quick fix to get this working’ is closed to new replies.