Contentful logo

Contentful Community

getUser / getAuthor?

Hi
How do I get the user / Author from a content type? (i’m using php sdk)

I know how to get for example getTitle and so forth.

Thankful for any help.

1 Like

Hey @john.svensson!

I don’t think it’s possible to get author of content type. Could you please provide a bit more context about your use case?
It’s possible to get user who created an entry and who updated it, i.e. https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/entries/entry/get-a-single-entry/console/php/.
You’ll get createdBy and updatedBy in scope of getEntry call.
Please let me know if I misunderstood your question.

1 Like

Tnx for the response! Really appreciate the help!

I’m like new to this, but I’m trying to create a blog-like site and want to output the author of every post. So you got it right! Tho I can’t seem to get createdBy and updatedBy in scope of getEntry call.

I tried the link you posted but my return-json doesn’t include anything close to author?

Am I missing something?

Hi @hej,

Because Contentful was designed as more of a content infrastructure than a turnkey CMS, some things work a little differently than you might expect. Authorship is one of them.

The “created_by” and “updated_by” are only available in the Management API for security and compliance reasons. If you’d like to show an Author, my recommendation would be this:

  1. Create an “Author” content type (bonus: you get to decide which fields an Author has)
  2. Create an “Author” entry for each author in your blog
  3. Add a single reference field called “author” to your “Post” content type. Go to settings and add a validation there, requiring only entries of type “Author”.

Now you can easily set who the author is for any post, independently of who actually entered the content (which is great if you have a more complex editorial workflow, with people reviewing or editing content on behalf of others).

Hope this helps!

2 Likes

Ah, tnx. I was thinking in terms of that, but I’m too hooked in WordPress-terms. :slight_smile:

Many thanks for this!
Regards John

2 Likes

Hi @hej !

Sure thing, always happy to help. And luckily, @pedro.carvalho explained solution way better than me :rofl:

1 Like