Skip Navigation

[Resolved] Display different information based on custom field in User registration Form

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to capture some user information in a field in a registration Form, then use that information to display different content conditionally on the site.

Solution: Use the following syntax in the WPBakery Page Builder to create a conditional based on a User field:

[wpv-conditional if="( '[types usermeta="select-employer-name" user_current="true" output="raw"][/types]' eq '295' )"]
{!{wpv-post-body view_template='template-for-employer-plans-benefits' item='295'}!}
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/customizing-sites-using-php/functions/

This support ticket is created 4 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1323751
custom-field-select-employer.png
employer-posts.png
ultimate-member-registration-info.png

We are using the Ultimate Member plugin manage our membership site (user registration / login, etc). There is an option within the Ultimate Member plugin to input a custom URL for redirect users after logging in. What should I input for the custom URL so that users are redirected to a custom post, that is associated with their "employer name" upon logging in?

See attached screenshot "ultimate member registration info" - I have inputted a custom field within the registration form called "member_name", but currently this is just a text field that the user types in when requesting a user account. (We are not allowed to display a dropdown of Employers for them to choose from, due to privacy policies).....

Is there a way that to manually associate each new WordPress user to a specific post ID so that they are redirected to a specific post ID (based on a custom field called "select_employer") in the "Employer Plans & Benefits" post type) upon logging in? I have attached screenshots for the custom post type, if it helps. Also, I am allowed to include hidden shortcodes within Ultimate Member registration form, if that helps too.

Thank you!!!

#1323919

Hi, it sounds tricky because you would need a way to get the Employer Plan post ID based on text typed by a User. That seems prone to failure, given that it's possible for multiple posts to have the same title, given that people make mistakes typing, given that there are different ways to abbreviate or not abbreviate, and so on. So unless you can specify a post ID for that Employer Plan post consistently, the redirect will not work consistently.

Is there any way the Users can be given their Employer Plan ID in advance? For instance, if you send an email to all the company employees with a special link URL that contains the employer plan ID like this:

<a href="<em><u>hidden link</u></em>">Create your account</a>

You could probably capture that in your registration form as a custom User field, and then redirect the user based on that URL using the wpv-post-url shortcode and a Types User field shortcode.

#1323967

Sure, we can give the Users their Employer Plan ID in advance. Can you give me some more detailed instructions on this part:
"You could probably capture that in your registration form as a custom User field, and then redirect the user based on that URL using the wpv-post-url shortcode and a Types User field shortcode."

Thank you!

#1324053
conditional-display-for-employers.png
custom-field-user-meta.png

So I have figured out a workaround using conditional displays. In my attached screenshots, you'll see I am using WPBakery PageBuilder... I created a custom user field using Types called "Select-Employer-Name" that a WordPress Admin will manually select for each new user. In my page, I'm using conditional output to display the corresponding post id for each Employer.

It was working about an hour ago, and now it's not - the items placed within the conditional output are not appearing at all on the page. I am testing on a different browser with a test user that has the "e294" custom field, and it should be outputting post ID 294. Can you please advise me, maybe my syntax for the conditional shortcode is incorrect?

Thank you!

#1324391

Hi, please try the following syntax for a conditional based on a User field value:

{!{wpv-conditional if="('{!{types usermeta='select-employer-name' user_current='true'}!}{!{/types}!}' eq 'e294')"}!}
  {!{wpv-post-body view_template='template-for-employer-plans-benefits' item='294'}!}
{!{/wpv-conditional}!}

Let me know if that's not working as expected.

#1324523

Hi Christian, looks like it is still not working as expected.

If it helps you troubleshoot, I see that the following snippet I am using to display a welcome text based on the user's select-employer-name value is working just fine and displaying the correct Employer Name.

<p style="text-align: right;"><span style="font-size: 16px; color: #ffffff; font-weight: 200;">TRUST MEMBER</span><span style="font-size: 16px; color: #ffffff; font-weight: bold;">
{!{types usermeta='select-employer-name' current_user='true'}!}{!{/types}!}
</span></p>

Please advise on how to make the content template display conditionally based on the logged in user meta value for select-employer-name.

#1324543
view-filters.png

Is there something I can do in the View for this to work? Or maybe the content template for the post? Please advise, as this is an urgent request.

#1324553

The first thing I would try is to use the square bracket syntax inside the condition like this:

{!{wpv-conditional if="('[types usermeta='select-employer-name' user_current='true'][/types]' eq 'e294')"}!}
  {!{wpv-post-body view_template='template-for-employer-plans-benefits' item='294'}!}
{!{/wpv-conditional}!}

If that doesn't work, I'll need to take a closer look.

#1324603

It did not work =( What do you need to take a closer look and advise?

#1324621

I need a login that will allow me to test this on the front-end of the site, and a login that will allow me to edit the template (if the two are different). Please let me know where I can see this on the front-end of the site, and which Content Template contains the code. Private reply fields are enabled here.

#1324671

Hi, I ended up editing the conditional for option 295. If you log in as the Miley user, you can see the results displayed now. Here is the template I was able to get working:

[wpv-conditional if="( '[types usermeta="select-employer-name" user_current="true" output="raw"][/types]' eq '295' )"]
{!{wpv-post-body view_template='template-for-employer-plans-benefits' item='295'}!}
[/wpv-conditional]

Please take a look and confirm that is working as expected, or let me know what's wrong.

#1324717
infinite-loop-error.png
content-missing-hradmintest.png
employer-plans-benefits.png
content-template.png

Hi, thanks so much for your help - you got the conditional display working, finally! The only problem now is that the output is not showing some of the interior tab contents (which are being pulled in through the "Benefits" post type in the content template we are outputting here: "Template for Employer Plans & Benefits) When testing in admin area, I see that there is an infinite loop error. This wasn't happening before the conditional display started working.... I see that the "Employer Plans & Benefits" posts are outputting just fine on their own individual posts though, so the issue is only appearing here. I've attached some screenshots. Please advise.

#1324829

My issue is resolved now. Thanks for your assistance with the conditional display portion. I was able to find a solution to the infinite loop error through Shane's post on a thread from 2 years ago. https://toolset.com/forums/topic/content-not-displayed-because-it-produces-an-infinite-loop-2/

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.