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 am trying to access data from some custom fileds in my MySQL db so that I can add them to a webpage that will be printed out. The data is held in a column called "paypal_user" and I need to access one piece of data and print that along with the user id of the user. I've had a little help with the code but I am stuck as I am getting the following error:

Call to undefined function get_user_meta()

My code is below. Thanks in advance for any help.

<?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>
share|improve this question
    
Doesn't show that for me in an external file. I see an error related to ABSPATH being defined already, but the rest seems to run ok. NOTE: regarding your code, echo '$user_ID' and echo '$exp_date' .. won't work, unless you're expecting to see literal variable names, remove the single quotes around the variables. –  t31os Mar 8 '11 at 13:16
add comment

1 Answer

up vote 0 down vote accepted

For one thing, you don't have to include wp-config or wp-db when you use wp-load. And as t31os says, single-quotes around variables will keep them from being interpreted by PHP.

<?php
include_once('wp-load.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">
/* styles go here */
</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>

Give that a shot. Works for me, assuming that you put this file in the same directory that wp-load.php lives in.

share|improve this answer
    
That works beautifully. Thanks very much! –  Micanio Mar 8 '11 at 15:09
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.