Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to get author in wordpress api react

import React, { Component } from "react"
...
class Blog extends Component {

   static async getInitialProps() {

      const postsRes = await fetch(`${Config.apiUrl}/wp-json/wp/v2/posts?_embed`)

      const post = await postsRes.json()

      return(post)

   }

render() {
   const posts = this.props.posts.map((post,index) => {
   return(
      <li key={index}>
         {post.better_featured_image != null ? <Feat img= 
         {post.better_featured_image.source_url}/> : ""}
         <Link
          as={`/blog/${post.slug}`}
          href={`/blog?slug=${post.slug}&apiRoute=post`}
         >
         <a>{post.title.rendered}</a>
         <p>{post.author}</p> //Returns ID I need name
         </Link>
       </li>
    )
   })
}
Never look this up again
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #author #wordpress #api #react
ADD COMMENT
Topic
Name
1+6 =