How to display plugin content in react using wordpress react API

Viewed 332

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?

1 Answers

This goes as standard WordPress wp-json format. Let's Suppose you are trying to get content of certain taxonomy (namely 'topic'),

This gives you the list of topics

/wp-json/wp/v2/topic/

If you want to get meta-data of specific topic

/wp-json/wp/v2/kb?topic=<topic_id>

If you want to get full details of specific page => /wp-json/wp/v2/kb?topic=<content_id>

Just keep in mind that post type is kb and then check on taxonomy

Related