Help with conditional shortcode for custom profile fields

Hi there.

I made a few custom fields on the registration form. I’m able to pull the data with get, but when I try to use conditionals the page breaks. Won’t save, won’t update, won’t load, I literally have to delete the page from the dashboard and start over.

Here is the code I’m hacking on unsuccessfully … is it possible to do what I’m attempting to do or am I just doing it wrong?

This works: Profile membership level: [s2Get user_field=“membership-level” /]

These don’t:

[s2If membership_level(Home-based Business)] Some words

[s2If user_field_membership_level(Home-based Business)] Some words


First, always copy and paste any code from the web into Notepad to strip off any crazy formatting. Then copy and paste that to your site. If you ever see squiggly quotes and not ’ or " then fix them. That should solve lots of errors. Not saying that’s an issue here, but it’s good practice.

I went to one of my functioning sites and found this. Hope it helps. I’ve never tried the shortcodes you’re trying.

[s2If current_user_can(access_s2member_level1)]
1 Like

Shortcodes don’t allow “new row”. Means, [ and ] should be on the same row, always.

Thanks. The code is all on the same row. Not sure why it pasted like that.

Conditionals work for other variables, just not the custom user fields I created. It’s weird.

Any other ideas?

Oh, understand… What you want needs some custom code - you must build the PHP function, that will compare the custom field’s value to some string, look at this hack. If you need a developer, please find me.

Thanks. I’ll see if my husband can take a crack at it. I may go in search of another platform tho. This one seems to have been abandoned by the developers from the forums I read last night :frowning:

I’m wondering why it pasted like that if you copied it from your site. Maybe there are crazy invisible characters that made it look like, but not really be, on the same line. Did you originally write it in Word? That always puts invisible crazy characters in. I’d try copying and pasting to notepad (or similar) and then copying and pasting back.

And the plugin was only formerly abandoned. @clavaque is in charge now working on updates.

1 Like

Hi Shannon.

Late last year some people were worried that may have been the case. I took over the plugin some months ago and it’s being taken care of.

You could have conditionals based on custom profile fields, but not like that. You can see here the ones s2If supports:

To do it with a custom field you’ll need to use a PHP condition. See:

WP Admin > s2Member > API / Scripting > Advanced PHP Conditionals

WP Admin > s2Member > API / Scripting > s2Member PHP/API Constants > S2MEMBER_CURRENT_USER_FIELDS

$fields = json_decode(S2MEMBER_CURRENT_USER_FIELDS, true);
if ($fields['membership_level'] == 'Home-based Business') { ?>
Some words
<?php } ?>

Having said that, why have the membership level as a custom field? Why not use the s2Member Level or a custom capability? And if you use these, you can use s2If for your conditionals.

Let me know if that helps. :slight_smile:

For custom profile fields, you could also try using the get_user_field() function.

<?php if (get_user_field('membership_level') == 'Home-based Business') { ?>
Say something
<?php } ?>

This is exactly what I needed. Thank you!

1 Like

To answer this question, we have different membership levels but want people to be able to register initially with a free account, which defaults to level 0. I don’t see a way for them to be able to choose what membership level they want to upgrade to other than clicking on the associated paypal button, and I don’t want the page cluttered with a bunch of buttons. So this way I figure I can display the appropriate subscription modification button based on the information I gathered when they registered. That said, the paypal subscription modification buttons don’t seem to work, so maybe you can tell me a better way to do it :slight_smile:

1 Like

Ah, that makes sense. Sounds like a good approach. Thanks for clarifying that.

Great! I’m very glad. :slight_smile: