Saturday, 26 December 2020

How to display plugin content in react using wordpress react API

I have a WordPress blog that is using a knowledge base plugin, now I would like to display content added to this KB to my react app using WordPress REST API.

Now I am able to display normal posts and pages from my wordpress app as follows

componentDidMount() {
    const wordPressSiteURL = clientConfig.siteUrl;

    this.setState( { loading: true }, () => {
        axios.get( `${wordPressSiteURL}/wp-json/wp/v2/posts/` )
            .then( res => {
                if ( 200 === res.status ) {
                    if ( res.data.length ) {
                        this.setState( { loading: false, posts: res.data } );
                        console.log('test', res.data)
                    } else {
                        this.setState( { loading: false, error: 'No Posts Found' } );
                    }
                }

            } )
            .catch( err => this.setState( { loading: false, error: err } ) );
    } )
}

Now How do I display my content from knowledge base (plugin) in my website to my react app?



from How to display plugin content in react using wordpress react API

No comments:

Post a Comment