This Bot Uses a WordPress Site’s REST API to Find All Posts & Pages Published. 

 July 12, 2020

By  Reed

This Ubot Studio bot was made to take advantage of the newly integrated REST API in WordPress.

If you don’t know, WordPress is a hugely popular Content Management System, that makes it easy to build and create websites that can do just about anything.

With much of the web being powered by WordPress (including this site), and the REST API being an excellent tool to combine with Ubot, it only seemed natural to build a bot in Ubot that used it!

The first place I wanted to start was to use Ubot to discover those possibilities… but this was a vague task. It wasn’t so apparent how I would navigate the REST API to discover all of the endpoints.

So, I decided to zero in on a more specific task.

Why not use Ubot to discover all of the published content on a WordPress site?

This is exactly what this bot accomplishes so far. With this bot you can discover all of the published posts, pages, and custom post types on a wordpress site.

This is valuable for a number of reasons. For one, it is much faster than using a web crawler to discover all published content a site powered by WordPress has. This is especially true when the crawling is headless (done without a graphical browser).

This ability became a core part of Static Generator, which enabled me to take the content Rest Explorer discovered and accomplish even more. You’ll see what I’m talking about when Static Generator is released.

Versions Available

So far I’ve made 2 different versions of this bot. The first version uses a premium Datatables plugin to display results in a table. The second uses no premium plugins and therefore can be used by every Ubot Studio owner.

The second version is available for download. The Datatables version has some more work left before it is ready.

Rest Explorer in action on my next favorite Ubot resource 😀

What I like about the second version is that it takes a lot of the complexity of working with a REST API by removing the need for knowing XPATH or REGEX. It does this by using a free JQuery library called Tabulator (which I talk about here along with an example bot), that has built in functions that can place JSON directly into an interactive table. This means that you can literally just scrape the JSON response from the API, and then bundle the responses together into a large JSON array that then loads into a nicely formatted table.

The real fun there is that this table gives you the option to save the data as a CSV file, which eliminates the need of converting JSON to CSV, eliminating the need for another premium plugin.

If you have been using Ubot Studio for some time now, then you will likely see how convenient this will be for you.

What it Does So Far

  • Discover all published Posts, Pages
  • Produce a table of them

This is a start, and can be an excellent start for the WordPress bots you wish to build. What can you do with a list of Posts? Pages?

Tweak it, extend it, learn from it. The source code is yours to mess with.

What it Will Do in The Future

The next step will be to have it find Types, which in WordPress speak entails Media and Custom Posts/Pages.

I’d like to add more fields to the table. Things like the published date come in handy when trying to determine how frequently updated a website is, or how old it is. So that will probably be next.

Eventually I want the Rest Explorer to help users understand what is available on the REST API for any WordPress site.

It would be awesome if they could use it to find new ways they can interact with their WordPress site using the API.

If you work with WordPress, definitely keep an eye on this one, and if you have ideas on ways to build this out better, do not hesitate to share. We benefit when we work together.

This bot is available to members only. Lifetime membership is available for a limited time during our launch phase, so join here. Once we have officially launched then membership will likely move over to a yearly access model, so take advantage of this while you can.

If you have any questions, feel free to get in touch.

Till next time!


Reed

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Subscribe to our newsletter now!

__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"d8d0c":{"name":"Main Color","parent":-1},"4a715":{"name":"Dark Accent","parent":"d8d0c"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"d8d0c":{"val":"rgb(26, 188, 156)","hsl":{"h":168,"s":0.75,"l":0.41}},"4a715":{"val":"rgb(21, 162, 136)","hsl_parent_dependency":{"h":168,"s":0.77,"l":0.35}}},"gradients":[]}}]}__CONFIG_colors_palette__
Subscribe
RSS
Follow by Email
YouTube
X

Forgot Password?

Join Us