ottieni l'ID dell'autore del post fuori dal ciclo
3 risposta
- voti
-
- 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; }
Con questafunzione sono statoin grado di visualizzare l'e-mail dell'autore delpostnella schermata dimodifica delpost.Non so ancora comefarlofunzionare conilmetafieldpersonalizzato,mapenso diesserepiù vicino ora.
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.
-
È anche unatua domanda.Puoimodificarloper chiarire.It's also your own question. You can edit it to clarify.
- 0
- 2014-06-17
- funwhilelost
-
- 2015-06-12
Ilmodopiù semplice sarebbe utilizzare
get_post_field()
:$post_author_id = get_post_field( 'post_author', $post_id );
Permaggiori dettagli su questoproblema: dai un'occhiata a questa risposta 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
Puoi utilizzare quanto segue:
/** * Ottiene l'autore delpost specificato.Puòessere utilizzato anche all'interno del loop *per ottenere l'ID dell'autore delpost corrente,senzapassare l'ID delpost. * Fuori dal ciclo devipassare un IDpost. * * @paramint $post_id ID delpost * @returnint ID dell'autore delpost */ funzione wpse119881_get_author ($post_id=0) { $post=get_post ($post_id); restituisci $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; }
-
Hmmnonfunzionaperme -penso che lafunzione debbaessere collegata a uno deifiltrimanon so quale.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
-
Perme funziona ... sei sicuro dipassargli un ID articolo (valido)?Works for me... are you sure you're passing it a (valid) post ID?
- 0
- 2013-10-24
- Stephen Harris
-
Ma voglio visualizzare questometa camponella schermata dimodificaper ognipost (non soloper uno)e l'autore delpostpuòessere diverso,quindi $post_id deveessere caricato dinamicamentein base alla schermata dimodifica.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
-
Imposta "$post_id" dinamicamente.Se si utilizza all'interno di unmetabox,il callback delmetabox verràpassato all'oggetto `$post`.Quindipuoi usare `$post-> ID` (Probabilmentepuoi semplicemente usare` $post->post_author`per quelmeta.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
Hobisogno diinserirenelmetabox della dashboard dimodificapost con l'e-mail dell'autore delpost (o altrimetacampi utente). Quindipuòesseremodificato quando l'amministratoreesamina questopost.
Questo codicefunziona quando $ user_id è unnumerointero (quando loinseriscomanualmenteperesempio 4)ma voglio ottenere dinamicamente l'ID dell'autore corrente (
$user_id
).get_the_author_meta('user_mail')
dovrebbefunzionare senza specificare$user_id
(codex dice che :))mail codice èinfunctions.php
e fuori dal cicloin modo chenonfunzioni. Stoiniziando con Wordpresse PHP quindinon so cosafare dopo.Hoprovato anche questo: