Post-Autoren-ID außerhalb der Schleife abrufen
3 Antworten
- Stimmen
-
- 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; }
Mit dieser Funktion konnteich die E-Mail des Postautorsim Bildschirmfür die Postbearbeitung anzeigen.Ich weißimmernochnicht,wieichesmit einembenutzerdefinierten Metafeldmachen soll,aberich denke,ichbin jetztnäher dran.
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.
-
Esist auch deineeigene Frage.Sie könnenes zur Verdeutlichungbearbeiten.It's also your own question. You can edit it to clarify.
- 0
- 2014-06-17
- funwhilelost
-
- 2015-06-12
Ameinfachsten wäre die Verwendung von
get_post_field()
:$post_author_id = get_post_field( 'post_author', $post_id );
Weitere Informationen zu diesem Problemfinden Sie unter dieser StackOverflow-Antwort .
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
Sie können Folgendes verwenden:
/** * 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,esfunktioniertbei mirnicht -ich denke,die Funktionmuss aneinen der Filter angeschlossen sein,aberich weißnicht,welcher.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
-
Funktioniertfürmich ... sind Sie sicher,dass Sieihmeine (gültige) Post-ID übergeben?Works for me... are you sure you're passing it a (valid) post ID?
- 0
- 2013-10-24
- Stephen Harris
-
Aberichmöchte dieses Meta-Feldim Bearbeitungsbildschirmfürjeden Beitrag anzeigen (nichtnurfüreinen) und der Autor des Beitrags kann unterschiedlich sein,so dass $post_identsprechend dem Bearbeitungsbildschirm dynamischgeladen werdenmuss.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
-
Setze `$post_id` dynamisch.Bei Verwendungin einer Metabox wird Ihrem Metabox-Rückruf das Objekt "$post" übergeben.Sie können also "$post-> ID" verwenden (Sie können wahrscheinlichnur "$post->post_author"für dieses Meta verwenden.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
Ichmuss die Metabox des Post-Edit-Dashboardsmit der E-Mail des Post-Autors (oder anderen Benutzer-Metafeldern)platzieren. Es kann alsobearbeitet werden,wenn der Administrator diesen Beitrag überprüft.
Dieser Codefunktioniert,wenn $ user_ideine Ganzzahlist (wennich dortbeispielsweise 4manuelleingefügt habe),ich aber dynamisch die aktuelle Autoren-ID abrufenmöchte (
$user_id
).get_the_author_meta('user_mail')
sollte ohne Angabe von$user_id
funktionieren (Codex sagt das :)),aber Codebefindet sichinfunctions.php
und außerhalb der Schleife,damitesnichtfunktioniert. Ichbeginne mit Wordpress und PHP,daher weißichnicht,wasich alsnächstestun soll.Auch versucht: