• I need to place in post edit dashboard metabox with post author e-mail (or other user meta fields). So it can be edited when admin reviews this post.

    $meta_id = get_the_author_meta( 'user_email', $user_id );
    
        $meta_box = array(
        	'id' => 'my-meta-box',
        	'title' => 'DANE FIRMY',
        	'page' => 'post',
        	'context' => 'normal',
        	'priority' => 'high',
        	'fields' => array(
        		array(
        			'name' => 'E-mail box',
           			'id' => 'mail',
        			'type' => 'text',
        			'std' => $meta_id
        		)
        	)
        );

    This code works when $user_id is an integer (when I manually put there for example 4) but i want to dynamically get current author id ( $user_id ).

    get_the_author_meta('user_mail') should work without specifying $user_id (codex says that :)) but code is in functions.php and outside the loop so it doesn’t work. I’m starting with WordPress and PHP so I don’t know what to do next.

    Also tried this:

    global $post;
    $user_id=$post->post_author;

  • The topic ‘get user id outside the loop’ is closed to new replies.