latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

retrieving custom fields

Home Forums Community Forum retrieving custom fields

This topic contains 6 replies, has 3 voices. Last updated by  boudewijn lutgerink 4 years, 6 months ago.

Topic Author Topic
Posted: Monday Jun 25th, 2012 at 8:25 am #17362

I use the 120622 version.
I created a custom field TAAL_LANGUAGE_SPRACHE, type drop down and did set it for my own profile to the correct value.
The purpose of this field is to determine the language of the user.
Values are:
NL|Nederlands
EN|English
DE|Deutsch

I tried to retrieve it with the following shortcode
[s2Get user_field="TAAL_LANGUAGE_SPRACHE" /]
(following the example from General Options -> Registration/Profile Fields & Options)
I don’t get any value back.
What am I doing wrong?

Another question in this context, is there a php function for this? I looked around and cannot find it.

** a while later **

I found that setting the field name in lowercase makes it work.
So the remaining Q is if there is a php function for this.
The reason I need this is for the following.
I have a site that serves multiple languages, Dutch, ENglish, German and Spanish.
I need to know the langiage of the user to have several widgets and menu items to (dis)appear.

List Of Topic Replies

Viewing 6 replies - 1 through 6 (of 6 total)
Author Replies
Author Replies
Posted: Monday Jun 25th, 2012 at 5:39 pm #17419

Hi Boudewijn.

The [hilite mono]get_user_field[/hilite] function can do that. http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_get_user_field%28%29

[hilite pre_code]
$my_field_data = get_user_field ("my_field_id"); # The Unique Field ID you configured with s2Member.
[/hilite]

I hope that helps. :)

Posted: Tuesday Jun 26th, 2012 at 2:15 am #17477

Sorry to say but no, it is NOT helping.
I tried that in this code:

<? php
    $Taal = get_user_field("taal_language_sprache");
   echo $taal;
?>

What I see on the page is : Do not access this file directly.

I probably do something wrong but I don’t see what.

When I leave the code out the page runs fine.

I just found out that now the [s2Get user_field="taal_language_sprache" /] is no longer working either.

>sigh< the wonderful world of a new development language…

Posted: Tuesday Jun 26th, 2012 at 11:52 pm #17612

Where are you trying the code?

In a WP page? When trying he PHP code, do you have a PHP execution plugin active?

If outside WP, then the s2Member function won’t work.

Do not access this file directly.

Could you post a copy of the full code you’re using?

Posted: Wednesday Jun 27th, 2012 at 2:33 am #17625

the s2Get shortcode was used directly in a WP page.
the PHP code was tried in a page (using the HTML tab), that only showed the code in the page, not quite what I wanted.
Using code insert manager plugin I tried that in the body of the page (before content) and in the after content.
I get no results anywhere.
I also found the PHP code widget, basically a text widget that can contain PHP code.
Tried it there, no results either.
Changing the get_user_field parameter to “user_login” makes it work, the function fails when I try a real user defined field.

Posted: Wednesday Jun 27th, 2012 at 8:20 am #17648
Raam Dev
Username: Raam
Staff Member

Boudewijn,

This code has two bugs:

<? php
    $Taal = get_user_field("taal_language_sprache");
   echo $taal;
?>

Notice the space after <? — that shouldn’t be there. Also, PHP variables are case-sensitive, so $Taal and $taal are different variables. Judging by your code, you meant for them to be the same. Here is the corrected code:

<?php
    $taal = get_user_field("taal_language_sprache");
   echo $taal;
?>

Also, if you’re trying to run PHP code in your WordPress Posts/Pages, you will need to install and activate a plugin such as Exec-PHP Plugin. PHP code will not run by default inside your WordPress Posts/Pages — this is a security feature imposed by WordPress.

Posted: Wednesday Jun 27th, 2012 at 12:07 pm #17659

I see, thanks, will give it a try.
as to your reply: “Judging by your code, you meant for them to be the same.”
The first developer who uses two “different” variables by the same name but different casing will be shot by me.
I may be new to PHP, I have 30+ years experience in software development. I NEVER EVER saw the use of case sensitivity for variables (hence my prevalence for languages such as VB, VB.Net and xBase and most definetely VFP)

a development tool should not try to act as a language teacher.

Viewing 6 replies - 1 through 6 (of 6 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.