Discover in this tutorial how to create a shortcode to display a list of active Easy Digital Downloads subscribers.
If you have a membership created with Easy Digital Downloads (plus Recurring Payments and Content Restriction addons) it is possible that more than once you have wanted to show the subscribers that are in it.
So in this tutorial you are going to see how to show a list of your Easy Digital Downloads membership’s active subscribers.
This would be the final result:
Are you interested in doing this? Then here is the code that you can use or make into your own variation.
Steps to display a loop of Easy Digital Downloads active subscribers
1. Create the shortcode
Add the following code snippet to your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
With this code you get to create a loop with EDD subscribers with the following data displayed:
- Image (avatar)
- Name
This is just an example. You can add or remove the fields you consider necessary using the function get_user_meta
.
In the loop arguments you indicate:
- To get the users with the role
edd_subscriber
- To be ordered taking into account the registration date
'orderby' => 'registered'
- To be ordered from oldest to newest (
ASC
) - To display 10 users.
You can modify the arguments you consider necessary.
Also, at the beginning of the loop you add a conditional with the function has_active_subscription
to show only the users who have an active EDD subscription.
2. Customize the subscribers list CSS
Now you just need to assign the styles to make it look the way you want it.
To do this, insert this block at the end of style.css:
To see this and another 1097 code snippets of this website, login or subscribe here.
When creating the shortcode you have used the classes subscribers-wrapper
and subscriber
, which allow you to layout the listing as you wish.
With these few lines of CSS you can make it look like the example I showed you at the beginning. But, as always, I invite you to customize it to your liking.
3. Add the shortcode where you want to display the subscribers loop
Finally, create the page where you want to display the list of subscribers and add the shortcode [edd_subscribers]
.
You got it.
Conclusions
Now you know how to display a list of active subscribers of a membership created with Easy Digital Downloads.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉