<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jack Lyons</title>
    <description>The latest articles on DEV Community by Jack Lyons (@jackedwardlyons).</description>
    <link>https://dev.to/jackedwardlyons</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F73900%2F72f0c9ec-8f4c-4027-95da-af53c67b8dc7.jpeg</url>
      <title>DEV Community: Jack Lyons</title>
      <link>https://dev.to/jackedwardlyons</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jackedwardlyons"/>
    <language>en</language>
    <item>
      <title>How to get all WordPress posts from the WP API with JavaScript</title>
      <dc:creator>Jack Lyons</dc:creator>
      <pubDate>Tue, 19 Mar 2019 17:54:00 +0000</pubDate>
      <link>https://dev.to/jackedwardlyons/how-to-get-all-wordpress-posts-from-the-wp-api-with-javascript-3j48</link>
      <guid>https://dev.to/jackedwardlyons/how-to-get-all-wordpress-posts-from-the-wp-api-with-javascript-3j48</guid>
      <description>

&lt;p&gt;&lt;em&gt;This post was originally published on my blog, &lt;a href="https://jacklyons.me/how-to-get-all-wordpress-posts-from-the-wp-api-with-javascript/"&gt;jacklyons.me&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Just recently I was asked to scrape a Wordpress blog for a client to audit of all their posts. Naturally, the first thought was to just export all the posts, however, after a quick  google I stumbled upon the &lt;strong&gt;&lt;a href="https://developer.wordpress.org/rest-api/reference/" rel="noopener"&gt;Wordpress REST API&lt;/a&gt;&lt;/strong&gt;. Using the API allows you to make direct requests to any wordpress site and retreive a list of blog posts as a JSON object.&lt;/p&gt;

&lt;p&gt;Give it a try right now. Punch this into your browser and  you should get a list of my 10 most recent blog posts:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;https://jacklyons.me/wp-json/wp/v2/posts&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It's that easy! Inside each post object there is a huge amount of data. You can extract things like post date, post status, and much more. The API documetation states that you can only retreive a maximum of 100 posts per request. In this post I'll show you how to create a function that will get all your posts in a single go! This can be helpful when the site you're scraping has hundreds or thousands of posts.&lt;/p&gt;

&lt;p&gt;Below I created a super simple HTML snippet that you can copy and paste into a basic HTML file. Note that I'm using some modern browser and ES2017 features so you'll have to use Chrome or Firefox. Also, it may take a little while if you are scraping a site with a few hundred or thousand posts.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;

&lt;p&gt;If you have any questions, comments or feedback to improve, please just leave a comment :)&lt;/p&gt;


</description>
      <category>wordpress</category>
      <category>javascript</category>
      <category>api</category>
      <category>asyncawait</category>
    </item>
  </channel>
</rss>
