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.

I have some custom user_meta fields in my MySQL database. The data is stored in my DB as follows:

the meta_key is called "paypal_user" and the info is stored in the meta_value column as:

O:11:"Paypal_User":9:{s:8:"duration";s:1:"1";s:13:"duration_type";s:1:"y";s:6:"amount";s:2:"30";s:8:"currency";s:3:"GBP";s:13:"last_pay_date";s:10:"2011-02-12";s:11:"expire_date";s:10:"2012-02-12";s:12:"account_type";s:7:"premium";s:10:"status_str";s:27:"Last payment was successful";s:12:"payment_type";s:12:"subscription";}

I need to print the "expire date" information on a webpage, as well as user_id and some form data s the user can print out a membership badge from the webpage.

How do I access that one particular part of the meta_data column?

Also, what do the numbers between each of the values in the meta_data column? I'm a newbie when it comes to using MySQL...

Thanks in advance.

Edit to add:

I'm posting my code as I can't seem to get it to work at all. Any pointers would be appreciated:

<?php
include_once('wp-config.php');
include_once('wp-load.php');
include_once('wp-includes/wp-db.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">

<!--    styling stuff -->

</style>
</head>

<body>
<div id="wrapper">

<div id="top_badge">

    <?php 

    if ( is_user_logged_in() ) {

    global $user_ID;

 // Get the 'paypal_user' info for the user. Just fetch a single
// value, not an array.
$paypal_user = get_user_meta($user_ID, 'paypal_user', true);
$exp_date = $paypal_user->expire_date;
?>

    <div id="member_no_1"><?php echo '$user_ID' ?></div>
    <div id="member_lp_1">PR34 2PL</div>
    <div id="member_exp_1"><?php echo '$exp_date' ?></div>

</div>
<?php } ?>
</div>

</body>
</html>

Thanks again.

share|improve this question
add comment

1 Answer

That's a serialized object variable. The numbers are string lengths, for example, where you see s:8:"duration", notice that the word 'duration' is 8 characters long. You shouldn't have to worry about that, because WordPress will take care of it for you.

You can access the fields like so:

global $user_ID;

// Get the 'paypal_user' info for the user. Just fetch a single
// value, not an array.
$paypal_user = get_user_meta($user_ID, 'paypal_user', true);
$exp_date = $paypal_user->expire_date;
$paytype = $paypal_user->payment_type;
share|improve this answer
    
I've tried using that code and I'm getting this error: PHP Fatal error: Call to undefined function get_user_meta(). I'm trying to access the database from outside Wordpress, if thats any help. –  Micanio Mar 4 '11 at 12:28
    
Ah, that would have been important to know. :) Assuming that you already fetched the data from the database into a variable called $mymeta, then do $paypal_user = unserialize($mymeta); –  Dougal Campbell Mar 4 '11 at 17:43
    
I've updated my question with my code as I am still having some issues - when I said it was outside Wordpress, what I meant was outwith the usual header info etc. I'm still within the same webspace. Sorry if I didn't make that clear. –  Micanio Mar 7 '11 at 14:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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