0

So I'm running a few ACF forms. One creates the post, and then I have an edit post form that edits the post via a form that populates based on the post id.

So my edit post url: site.com/edit-post/?post=478

Then I have some code in my file:

    <?php 

        $post_id = $_GET["post"];

This effectively lets me get the current post ID based on the ID passed in the URL. It works well for my forms. The issue I'm having is I want to display the author name for the post in the URL, however I can't seem to find the right syntax to do it. I've tried the_author(); and it doesn't give me the right author.

Additionally, I tried the_author_meta( 'display_name', $post_id['post_author'] ); and it gave me a different author name but still not the right author for the post.

Any ideas as to what I could try to get this working?

Thanks, let me know if you need more info.

  • if $post_id is the ID, then you should pass $post_id, not $post_id['post_author'] – Milo Mar 20 '18 at 15:24
0

You get the author ID of the post ID via get_post_field

$post_author_id = get_post_field( 'post_author', $post_id );

With this post ID you get all author meta data, also the name like

the_author_meta( 'display_name', $post_author_id );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.