if(strpos($query, '%get_email%') !== false){
        $query = str_replace('%get_email%',  get_the_author_meta( 'user_email' ), $query);

Okay so am trying to make a MySQL query and in the plugin I am trying to add a shortcode %get_email% but anyway its not returning any email in the actual query.

Like select* from from tablename where email='%get_email%';

Any idea on how to do that?

Here what is working for id -

    if(strpos($query, '%CURRENT_USER_ID%') !== false){
        $query = str_replace('%CURRENT_USER_ID%', get_current_user_id(), $query);
  • What is $query? What is the context? I am unsure what you are doing. – s_ha_dum May 22 '15 at 21:52

I will approach like this:

global $current_user;

$email = (string) $current_user->user_email;

You just called got the email from the current_user array and cast it into string :) that's it


If you just need to "Get Current user email as a return string value" then you can simply do this by using following function

// Add this function in your functions.php or in your plugin
function mm_get_current_user_email(){
    global $current_user;

    $email = $current_user->user_email; 

    return $email;  
add_shortcode( 'get_email', 'mm_get_current_user_email');

Then you can get current user email as string where ever you want by simply using [get_email] or <?php echo do_shortcode( '[get_email]' ); ?>

For more on get_currentuserinfo() visit WordPress Codex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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