Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

How do you display the content from another WordPress site/database?

Does anyone have insight into displaying loop content from another WordPress site/database?

1 Answer

There are a couple of ways you could do this

  1. Using the Rest API http://v2.wp-api.org/: This would allow you to fetch the content from the API remotely. You could then use JavaScript for example, to take the JSON from whatever content endpoint you consume, and then output it onto the page.

  2. Using WPDB to connect to a different database like in the answer to this question: http://wordpress.stackexchange.com/questions/1604/using-wpdb-to-connect-to-a-separate-database Essentially you'd be using WPDB to construct a custom query to the other database (assuming its on the same server). From there outputting the data should be mostly the same as a standard content query.

  3. Using the HTTP API: https://codex.wordpress.org/HTTP_API , the post here http://wordpress.stackexchange.com/questions/7152/displaying-content-from-one-wp-site-on-separate-wp-site has an excellent example of getting content from another WP site remotely and then working with it to output the content.