Display data based upon a template

I am helping a non-profit. People will see a QRcode for a specific business and scan it. It contains a link such as: https://whoami.com/lookup?businessid=123

That link will take them to a single page which will display specific information based upon the business ID. This Business ID is not a part of he WordPress standard account but an S2member item for an existing ID.

On the single page would be

[s2Get user_field="businessaddress" user_id=$businessid /]
[s2Get user_field="directions" user_id=$businessid /]

This keeps me from having to create a page for each business.

Is this something that would work? If so, please point me in the right direction. I have played around with $_GET[‘id’]; but am not the programmer I used to be (back when we had real toggle switches and punch cards)!`

Hi Mark,

To use the ID var in the s2Get shortcode, you’d need some PHP, in which case you could just use the get_user_field directly. https://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_get_user_field()

E.g. (not tested):

<?php echo get_user_field('businessaddress', (int) $_GET['businessid']); ?>

Of course, you’d need a PHP execution plugin for that to work on a WP page.

I’m assuming that businessid is a WP user ID, if not, you’d need some other code to find the user that has that business ID in his profile.


Thanks. I changed the variables some, but here is what worked for me.

<?php $passport = get_user_option('s2member_custom_fields', (int) $_GET['id']); ?>

and then echo out the fields I need from the custom fields.

I was going to try to use an S2 custom field that I created instead of the Wordpress user ID, but I think I am happy enough to leave things as they are. There is always another day :slight_smile:

1 Like

Cool :slight_smile:

Thanks for the info that put me on the right path! I was able to get the whole process to work, and will document it here as an exercise for others it might help.

We call it a Passport as a promotional name because people are getting off a cruise ship, scan a QR code and get info about a members company, like a restaurant that offers discounts. :slight_smile:

A visitor scans a QR Code (each one similar but differing with a code. That code I use is the WP ID of a member company). The display will show information about that company.

I have 1 page (passportpage) which displays the optional S2 data fields for the company and am using (for convenience) an XYZ PHP Code snippet to grab the ID parameter from the URL, then pull the S2 record and display the fields.

I opted to use the WP User ID rather than an S2 field I could create for a code. I think the WP lookup of ID will be faster and it reduces the need for me to fill in another field. The WP ID is created automatically with Wordpress. It can be displayed in the Admin User listing if you use a plugin like SHOW USER ID.

Now I just create a QR code which equates to the URL as follows a https://mysite.com/passportpage?ID=123 and member with ID=123 has his S2 fields displayed.

The snippet below is called PASSPORT and the passportpage uses the shortcode [xyz-ips snippet=“passport”] to display the data.

If a member is demoted, he is no longer level 1 OR if he decides to go to his Profile Page and check NO for ACTIVE, then his passport no longer shows up. The q fields listed are the optional S2 fields I created for this project.

$s2member_access_role = get_user_field ("s2member_access_role", (int) $_GET['id']);
$passport = get_user_option('s2member_custom_fields', (int) $_GET['id']);

// To display the Passport Info the member must allow it AND the must be a Full Member (level 1) or 4
if (($s2member_access_role == "s2member_level1" || $s2member_access_role == "s2member_level4") & $passport[q_active] == "Y")
  echo "Company<br>" . $passport[q_company];
  echo "<p>Location<br>" . $passport[q_location];
  echo "<p>Directions<br>" . $passport[q_directions];
  echo "<p>Distance From Pier<br>" . $passport[q_distance];
  echo "<p>Map ID<br>" . $passport[q_mapid];
  echo "<p>Special Offered<br>" . $passport[q_special];
  echo "<p>Telephone<br>" . $passport[q_telephone];
echo "<p>Sorry, This Passport Is Not Active at this time!";

Because some users might be using cellphones, I also used a plugin to ensure that the data will fit on their screens and I don’t have to add code on the original passport page to accommodate special screen sizes.

1 Like

Nice job! Thank you for sharing that, Mark! :slight_smile: