How to query all Easy Digital Downloads products

While there is an API for working with Easy Digital Downloads data, sometimes you might just want to fetch all the downloads you have or query for a specific one.

Downloads are just stored as posts with the post_type of download so just do a get_posts call for them:

	$posts = get_posts( array(
			'post_type' => 'download',
			'post_status' => 'any',
			'suppress_filters' => true,
			'posts_per_page' => -1,

You can add parameters like meta_key and meta_value to search for specific downloads as needed.

Once you get the posts just loop through and create a new EDD_Download object for them:

	$downloads = array();
	foreach ( $posts as $post ) {
		$downloads[] = new EDD_Download( $post->ID );

One things that tripped me up was some downloads not being returned.  If you’re using the EDD Hide Downloads extension, you’ll need to remove those filters before you call get_posts():

	if ( class_exists( 'EDD_Hide_Download' ) ) {
		remove_filter( 'edd_downloads_query', array( EDD_Hide_Download::get_instance(), 'shortcode_query' ) );
		remove_action( 'pre_get_posts', array( EDD_Hide_Download::get_instance(), 'pre_get_posts' ), 9999 );

then likely add them back afterwards if you’re still outputting something else during the request.