Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

get_user_meta returning null. WordPress

  • SOLVED

I'm trying to get the user information when using a custom endpoint. It's not returning any data from get_user_meta. Am I missing an include or something?

My code looks like:

<?php

if ( !defined('ABSPATH') ) {
/** Set up WordPress environment */
echo "No ABSPATH!";
require_once( '../../../wp-load.php');
}

notify_user();

function notify_user() {
$authid = 4;
$email = get_user_meta($authid, 'user_email', true);
$firstname = get_user_meta($authid, 'user_nicename', true);

mail ($email, "Subject", "Hello" . $firstname);

}

?>

Answers (3)

2015-04-06

Arnav Joy answers:

try this

$user_email = get_the_author_meta( 'user_email',$authid );

https://codex.wordpress.org/Function_Reference/get_the_author_meta


testimonials comments:

This one's a winner. Not sure why it doesn't like the get_user_meta, but get_the_author_meta seems to be happy.

Thanks!

2015-04-06

Luis Abarca answers:

Try to initialize the wp object.


if ( !defined('ABSPATH') ) {
/** Set up WordPress environment */
echo "No ABSPATH!";
require_once( '../../../wp-load.php');
wp();
}

2015-04-06

Dbranes answers:

I think the problem is that user_email and user_nicename are part of the wp_user table and not inside your wp_usermeta table.

You should therefore to try this:

$user = get_user_by('id', 4);
$nicename = $user->user_nicename;



ps: I would recommend using a custom rewrite endpoint instead with <em>add_rewrite_endpoint</em> or consider using <em>admin-ajax.php</em>.


testimonials comments:

Thanks for the hint on the rewrite endpoint, but this one will only be used in one place, and the rest of the script is locked down.