Give 1.8.14 – Introducing the new Give_Donors_Query class

In Give version 1.8.14, We are introducing the new Give_Donors_Query class which will help developers to query donors more easily and efficiently with less code. [Read]

Here is a general code sample query parameters for Give_Donors_Query:

$donor = new Give_Donors_Query(array(
    'number'     => 20,
    'offset'     => 0,
    'paged'      => 1,
    'orderby'    => 'id',
    'order'      => 'DESC',
    'user'       => null,   // Single or array of user ids
    'email'      => null,   // Single or comma seperated emails
    'donor'      => null,   // Single or array of donor ids
    'meta_query' => array(),
    'date_query' => array(),
    's'          => null,   // search string with prefix name: or note:
    'fields'     => 'all', // Support donors (all fields) or valid column  as string or array
    'count'      => false, // Set to true to get donor count for current query
));

Another demo query for the Give_Donors_Query class:

1. Get donors and sort by total donation amount:

$donors = new Give_Donors_Query(array(
    'number'     => -1,
    'orderby'    => 'purchase_value',
));
$donors = $donors->get_donors();

2. Get donors and sort by total donation count:

$donors = new Give_Donors_Query(array(
    'number'     => -1,
    'orderby'    => 'purchase_count',
));
$donors = $donors->get_donors();

3. Get information about specific donors:

$donors = new Give_Donors_Query(array(
    'donor'    => array( 11, 45, 67 ),
));
$donors = $donors->get_donors();

4. Get the total number of donors:

$donors = new Give_Donors_Query(array(
    'number' => -1,
    'count' => true,
));
$donors = $donors->get_donors();

This class was created because we found it difficult and cumbersome to do more complex donor queries. We will continue to optimize the class as we move forward. Please let us know if you find any issues on GitHub.

 

Ravinder Kumar

Open source lover, the father of a daughter, continually improving developer, and Senior WordPress Engineer at GiveWP.

 

One thought on “Give 1.8.14 – Introducing the new Give_Donors_Query class

Leave a Comment