How to get membershiplevel from WordPress Database?

It seems that s2Member does not bring the functionality out of the box. So I may not have a direct answer to your question, but a few suggestions instead:

  • In your case I would probably try to combine s2Member with myCred (https://mycred.me/add-ons/badges/) for example like this: the only way to earn ‘points’ would be upgrading to a pro account / role. Then a badge would be applied and displayed respectively.

  • Another option could be to use get_queried_object to get the user role – then adjust the output accordingly: “Show different badge based upon the user role

  • A third probably a but more complex option could be to use the plugin BadgeOS: ‘… a powerful free plugin to WordPress that lets you easily create achievements and issue sharable badges as your users succeed. ‘ (http://badgeos.org/)

  • Last but not least: I’m personally actually using PMPro instead of s2members – and they offer an add-on that would do just that: ‘Assign unique member badges (images) to each membership level and display via a shortcode or template PHP function’ (https://www.paidmembershipspro.com/add-ons/plus-add-ons/member-badges/)