Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I reach a specific userdata in the database, when that field has a dash (hyphen) - in the slug?

I use the plugin WP-Members.

I have created a new userdata field with the plugin with the name date-of-birth - by mistake I used these dashes - instead of underscores _. In the database (the usermeta table) it now looks like:

Database screenshot

I get the userdata with these two lines:

$user_data = get_userdata( $user_id );
$user_data->user_email;

which works for all fields - exept those with dashes in them! I have tried this:

$user_data = get_userdata( $user_id );
$user_data->date-of-birth;

which just returns 0. And this:

$user_data = get_userdata( $user_id );
$user_data->date_of_birth;

which of course doesn't work (it gives null), since that is not the correct name.

Is there a method to reach this field with dashes in the slug?

Note I can't change the slug. That is not allowed by this plugin after the field is created.

share|improve this question
    
Pure PHP magic (or madness) as per answer, not in scope. :) –  Rarst Sep 22 '13 at 21:48
add comment

closed as off-topic by Rarst Sep 22 '13 at 21:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions should be specific to WordPress within defined scope (merely happening in its context, such as generic PHP/JS/HTML/CSS, is insufficient). Might be better asked at Stack Overflow or other appropriate site of Stack Exchange network." – Rarst
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 2 down vote accepted

Try this:

$user_data = get_userdata( $user_id );
$user_data->{'date-of-birth'};

It's weird looking but should work. :-)

share|improve this answer
1  
Perfect. This works. –  Steeven Sep 23 '13 at 7:03
    
Happy to help...! –  Eric Sep 23 '13 at 15:29
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.