Often times you may want to display donor information on your website from Give. The following will demonstrate how to do this using Give’s core classes. Keep in mind, not all donors want their information displayed publicly.

Getting Donors from Your Give Database

The key to getting donors from your database is using the Give_Donors_Query class.

Get the latest 20 Give Donors

/**
 *  QUERY 1: Basic Example
 *
 *  This query outputs the latest 20 donors
 *  in an ordered list
 */

// Query 1 Argument
$args = array(
        'number' => 20
);

$loop1 = new Give_Donors_Query( $args );
$loop1 = $loop1->get_donors();


if ( $loop1 ) {
    ?>
    <h2>Output latest 20 Donors</h2>
    <hr />
    <ol>
        

            <li><strong>name ); ?> </strong></li>
            
    </ol>
    
    <!-- If you don't have donations that fit this query -->
    <h2>No Donors, yet.</h2>
    <?php
}

Understanding all the data you can Query for Donors

Often the easiest way to query data is to see a dump of the data to be able to customize the query. In the above snippet you pulled the name for each donor with $donor->name object/key.

The following snippet will similarly query the Give Donor Object, but instead of returning 20 Donors, it will return one donor, and all of the various attributes of that object.

Note: Give’s Donor Wall is a method for displaying donors on the front end of the site that respects the “anonymous” status of donations. The following tutorial will display donors regardless of “anonymous” status of the donation.

Get all data to use in Donor Queries

$testquery = new Give_Donors_Query( array( 'number' => 1 ) );
$donors    = $testquery->get_donors();

if ( $donors ) {
	foreach ( $donors as $donor ) {
		$meta = $donor;
		?>
        <div style="background: red;color: black;padding: 2rem">
            <h3>Test Data</h3>
            <p>The following outputs all the "give_donor" fields for you to reference in building out your
                donor list</p>
            <p style="color:black"></p>
        </div>
		<?php
	}
}

Conclusion

That gives you a starting point to pull any data you’d like for Donors from your Give database.