obtenir l'identifiant de l'auteur du message en dehors de la boucle
3 réponses
- votes
-
- 2013-10-24
add_action( 'edit_form_after_title', 'myprefix_edit_form_after_title' ); function myprefix_edit_form_after_title() { global $post; $author_id=$post->post_author; $authord = get_the_author_meta( 'user_email', $author_id); echo $authord; }
Avec cettefonction,j'aipu afficher l'e-mail de l'auteur dumessage dans l'écran d'édition dumessage.Jene saistoujourspas comment lefairefonctionner avec un champmétapersonnalisé,maisje pense queje suisplusprochemaintenant.
add_action( 'edit_form_after_title', 'myprefix_edit_form_after_title' ); function myprefix_edit_form_after_title() { global $post; $author_id=$post->post_author; $authord = get_the_author_meta( 'user_email', $author_id); echo $authord; }
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.
-
C'est aussi votrepropre question.Vouspouvez lemodifierpour clarifier.It's also your own question. You can edit it to clarify.
- 0
- 2014-06-17
- funwhilelost
-
- 2015-06-12
Lemoyen leplus simple serait d'utiliser
get_post_field()
:$post_author_id = get_post_field( 'post_author', $post_id );
Pourplus de détails sur ceproblème: consultez cette réponse StackOverflow .
The easiest way would be using
get_post_field()
:$post_author_id = get_post_field( 'post_author', $post_id );
For more details on this issue: have a look at this StackOverflow answer.
-
- 2013-10-23
Vouspouvez utiliser les éléments suivants:
/** * Gets the author of the specified post. Can also be used inside the loop * to get the ID of the author of the current post, by not passing a post ID. * Outside the loop you must pass a post ID. * * @param int $post_id ID of post * @return int ID of post author */ function wpse119881_get_author( $post_id = 0 ){ $post = get_post( $post_id ); return $post->post_author; }
You can use the following:
/** * Gets the author of the specified post. Can also be used inside the loop * to get the ID of the author of the current post, by not passing a post ID. * Outside the loop you must pass a post ID. * * @param int $post_id ID of post * @return int ID of post author */ function wpse119881_get_author( $post_id = 0 ){ $post = get_post( $post_id ); return $post->post_author; }
-
Hmm celane fonctionnepaspourmoi -je pense que lafonction doit être accrochée à l'un desfiltresmaisje ne saispas lequel.Hmm it doesnt work for me - i think function must be hooked to one of filters but dont know which.
- 0
- 2013-10-24
- th3rion
-
Fonctionnepourmoi ... êtes-vous sûr de luitransmettre unidentifiant depublication (valide)?Works for me... are you sure you're passing it a (valid) post ID?
- 0
- 2013-10-24
- Stephen Harris
-
Maisje veux afficher ce champméta dans l'écran d'éditionpour chaque article (pas seulementpour un)et l'auteur de l'articlepeut être différent,donc $post_id doit être chargé dynamiquementen fonction de l'écran d'édition.But i want to display this meta field in edit screen for every post (not just for one) and post author can be different so $post_id must be loaded dynamically according to edit screen.
- 0
- 2013-10-24
- th3rion
-
Définissez `$post_id` dynamiquement.Si vous utilisez dans unemetabox,votre callbackmetabox recevra l'objet `$post`.Vouspouvez donc utiliser `$post-> ID` (vouspouvezprobablement simplement utiliser` $post->post_author`pour cetteméta.Set `$post_id` dynamically. If using inside a metabox, your metabox callback will be passed the `$post` object. So you can use `$post->ID` (You can probably just use `$post->post_author` for that meta.
- 0
- 2013-10-24
- Stephen Harris
Je doisplacer dans lamétabox dutableau debordpost-édition avec l'e-mail de l'auteur dupost (ou d'autresméta-champs utilisateur). Ilpeut donc êtremodifié lorsque l'administrateurexamine cemessage.
Ce codefonctionne lorsque $ user_idest unentier (lorsqueje lemetsmanuellementparexemple 4)mais queje veux obtenir dynamiquement l'ID de l'auteur actuel (
$user_id
).get_the_author_meta('user_mail')
devraitfonctionner sans spécifier$user_id
(le codex dit cela :))mais le codeest dansfunctions.php
et en dehors de laboucle donc çane marchepas. Je commence avec Wordpresset PHP doncje ne saispas quoifaireensuite.A égalementessayé ceci: