Import post from WordPress RSS feed

🔥 This query is already included in Gato GraphQL, as Persisted Query “Import post from WordPress RSS feed”.

This query imports a post from a WordPress RSS feed, using the title, content and excerpt of the post.

If the author with that username exists locally, it uses it, otherwise it replaces it with the one defined via variable $defaultAuthorUsername.

Variable $url receives the URL of the WordPress single post's RSS feed. It usually is the blog post URL + "/feed/rss/?withoutcomments=1". Eg:

https://mysite.com/blog/hello-world/feed/rss/?withoutcomments=1
query GetPostFromRSSFeedAndExportData(
$url: URL!
) {
_sendHTTPRequest(input: {
url: $url,
method: GET
}) {
body
rssJSON: _strDecodeXMLAsJSON(
xml: $__body
alwaysArrayTagNames: [
"category",
],
)

# Fields to be imported
authorUsername: _objectProperty(
object: $__rssJSON,
by: {
path: "rss.channel.item.dc:creator"
}
)
@export(as: "authorUsername")

# categorySlugs: _objectProperty(
# object: $__rssJSON,
# by: {
# path: "rss.channel.item.category"
# }
# )

content: _objectProperty(
object: $__rssJSON,
by: {
path: "rss.channel.item.content:encoded"
}
)
@export(as: "content")

excerpt: _objectProperty(
object: $__rssJSON,
by: {
path: "rss.channel.item.description"
}
)
@export(as: "excerpt")

title: _objectProperty(
object: $__rssJSON,
by: {
path: "rss.channel.item.title"
}
)
@export(as: "title")
}
}

# If the author's username exists in this site, keep it
# Otherwise, use the default one
query CheckAuthorExistsOrChange(
$defaultAuthorUsername: String! = "admin"
)
@depends(on: "GetPostFromRSSFeedAndExportData")
{
existingUserByUsername: user(by: { username: $authorUsername })
{
id
username
}
userExists: _notNull(value: $__existingUserByUsername)
username: _if(
condition: $__userExists,
then: $authorUsername,
else: $defaultAuthorUsername
)
@export(as: "existingAuthorUsername")
}

mutation ImportPostFromWPRSSFeed
@depends(on: "CheckAuthorExistsOrChange")
{
createPost(input: {
status: draft,
authorBy: {
username: $existingAuthorUsername
},
contentAs: {
html: $content
},
excerpt: $excerpt
title: $title
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
slug
date
status

author {
id
username
}
content
excerpt
title
}
}
}

Extensions required for this query permalink

  1. Field To Input permalink

    Retrieve the value of a field, manipulate it, and input it into another field or directive, all within the same operation.

  2. Helper Function Collection permalink

    Collection of fields providing useful functionality.

  3. HTTP Client permalink

    Addition of fields to execute HTTP requests against a webserver and fetch their response.

  4. Multiple Query Execution permalink

    Combine multiple queries into a single query, sharing state across them and executing them in the requested order.

  5. PHP Functions via Schema permalink

    Manipulate the field output using standard programming language functions available in PHP.

Bundles containing all extensions required for this query permalink

  1. “All in One Toolbox for WordPress” Bundle permalink

    Achieve all superpowers: All of Gato GraphQL extensions, in a single plugin

  2. “Better WordPress Webhooks” Bundle permalink

    Easily create webhooks to process incoming data from any source or service using advanced tools, directly within the wp-admin

  3. “Private GraphQL Server for WordPress” Bundle permalink

    Use GraphQL to power your application (blocks, themes and plugins), internally fetching data without exposing a public endpoint

  4. “Selective Content Import, Export & Sync for WordPress” Bundle permalink

    Import hundreds of records into your WordPress site from another site or service (such as Google Sheets), and selectively export entries to another site

  5. “Tailored WordPress Automator” Bundle permalink

    Create workflows to automate tasks (to transform data, automatically caption images, send notifications, and more)

  6. “Versatile WordPress Request API” Bundle permalink

    Interact with any external API and cloud service, posting and fetching data to/from them

Tutorial lessons explaining how the query works permalink