1

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>
1
  • 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. Commented Mar 8, 2011 at 13:16

1 Answer 1

0

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.