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 easiest way would be using
get_post_field()
:For more details on this issue: have a look at this StackOverflow answer.
You can use the following:
With this function I was able to display post author e-mail in post edit screen. Still don’t know how to make it work with custom meta field but I think Im closer now.