ZWW的博客

大家好,欢迎来到小Z的突发奇想圈,这里有各种小Z发明的小玩具、个人动态、突发奇想的小技巧。

使用macos快捷指令实现快速创建一篇WordPress文章

为什么要这么做?

小Z比较喜欢折腾,喜欢做些小玩意儿,有时突然冒出个想法,但又找不到快捷的记录方法,即使有(如手机上的备忘录),过段时间也会忘了处理,所以想自己弄个快捷入口,输入一个标题即成为一个待办,有时间了就打开看看并深度思考一下,处理之,并记录成一个过程文档,这样既能释放分享欲又能学到一些东西。

所以,本文目的仅仅是创建文章的标题或者说是一个TODO事项。

Table of Contents
  1. 为什么要这么做?
  2. WordPress支持API调用吗?
  3. WordPress的baseUrl是什么?
  4. WordPress的创建文章接口是什么?
  5. WordPress的传参是怎样的?
    1. Create a Post
      1. Arguments
  6. 如何认证呢?总不能任何人都可以在我的网站上发布文章吧
  7. Apifox测试接口调用
  8. 开始制作快捷指令
    1. 构思

WordPress支持API调用吗?

既然想外部调用Wordpress,首先先看看它是否支持api调用。

WordPress支持API方式调用吗
AI说支持的,并且是内置的(😁,这个AI后续可能会分享)。

WordPress的baseUrl是什么?

先问问AI

WordPress的baseurl是什么?

奥,AI说是:https://your-site.com/wp-json/wp/v2

WordPress的创建文章接口是什么?

那就搜索一下看看,找到了:/https://developer.wordpress.org/rest-api/reference/posts/

WordPress的传参是怎样的?

Create a Post

如下:

Arguments

dateThe date the post was published, in the site’s timezone.
date_gmtThe date the post was published, as GMT.
slugAn alphanumeric identifier for the post unique to its type.
statusA named status for the post.
One of: publishfuturedraftpendingprivate
passwordA password to protect access to the content and excerpt.
titleThe title for the post.
contentThe content for the post.
authorThe ID for the author of the post.
excerptThe excerpt for the post.
featured_mediaThe ID of the featured media for the post.
comment_statusWhether or not comments are open on the post.
One of: openclosed
ping_statusWhether or not the post can be pinged.
One of: openclosed
formatThe format for the post.
One of: standardasidechatgallerylinkimagequotestatusvideoaudio
metaMeta fields.
stickyWhether or not the post should be treated as sticky.
templateThe theme file to use to display the post.
categoriesThe terms assigned to the post in the category taxonomy.
tagsThe terms assigned to the post in the post_tag taxonomy.

要这么多传参啊,我先测试一下,其实我只想创建一个带有标题的文章草稿。

如何认证呢?总不能任何人都可以在我的网站上发布文章吧

先看看AI怎么说:

配置API请求认证

经过验证,可以的。

Apifox测试接口调用

  1. 设置认证信息
wordpress认证配置
wordpress创建文章接口测试

开始制作快捷指令

构思

手机端点击快捷指令,弹出输入框,输入要创建的文章标题。

电脑端使用快捷键触发,同样弹出输入框,输入要创建的文章标题。

然后调用WordPress创建文章接口即可。直接分享做好的快捷指令。

https://www.icloud.com/shortcuts/dc39d95ab21b4d3e870956409e500db1

⚠️:快捷指令获取后,先填入前三个文本,分别为:用户名、应用密码(非登陆密码)、api地址(https://your-site.com/wp-json/wp/v2

《“使用macos快捷指令实现快速创建一篇WordPress文章”》 有 1 条评论

  1. […] 使用macos快捷指令实现快速创建一篇WordPress文章 […]

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注