获取所有帖子通过 xmlrpc 请求从 WordPress 博客获取 ID
我没有在 WordPress Codex 中找到任何 xmlrpc 方法调用来执行此操作。 我可以通过metaWeblog.getRecentPosts 获取所有帖子并提取ID,但我并不确切知道博客中帖子的数量。
I didn't find any xmlrpc method call to do it in WordPress codex.
I can get all the posts via metaWeblog.getRecentPosts and extract IDs, but I didn't exactly know the count of the posts in blog.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有一种 XML-RPC 方法可以获取所有帖子,主要是因为这可能会导致严重的性能问题(想象一个具有 5,000 个帖子和高流量的博客......尝试解析所有内容的列表会导致一些严重的服务器延迟)。
使用 WordPress 常用方法最接近的方法是使用
getRecentPosts
调用:blogger.getRecentPosts
和metaWeblog.getRecentPosts
(MetaWeblog 调用实际上是只是 Blogger 调用的别名)。也就是说,您可以创建自己的方法来返回已发布帖子的计数或已发布帖子的 ID 列表。只需创建一个快速插件来连接到 XML-RPC 系统即可添加端点和方法:
该代码块将向您的 XML-RPC 系统添加两个新调用:
myNamespace.postCount
和myNamespace.postIDList
。您可以远程调用它们以分别返回已发布帖子的计数和已发布帖子 ID 的列表。您还需要定义将处理请求的 PHP 函数 - 所有 XML-RPC 系统都会将远程请求路由到返回数据的内部 PHP 函数:
就是这样。将所有代码集中到一个自定义插件中,将其放置在您的站点中,激活它,您现在可以通过 XML-RPC 获取已发布帖子的计数或已发布帖子 ID 的列表。
There isn't an XML-RPC method to get all posts, mostly because that could lead to significant performance issues (imaging a blog with 5,000 posts and high traffic ... trying to parse a list of everything would cause some serious server lag).
The closest you can get with stock WordPress methods would be with the
getRecentPosts
calls:blogger.getRecentPosts
andmetaWeblog.getRecentPosts
(the MetaWeblog call is actually just an alias to the Blogger call).That said, you can create your own method that returns either a count of published posts or a list of the IDs of the published posts. Just create a quick plug-in to hook into the XML-RPC system to add your endpoint and method:
That code block will add two new calls to your XML-RPC system,
myNamespace.postCount
andmyNamespace.postIDList
. You can call these remotely to return a count of published posts and a list of published post IDs, respectively.You also need to define the PHP functions that will handle the request - all the XML-RPC system does it route remote requests to internal PHP functions that return data:
That's it. Pull all the code together into a custom plug-in, place it in your site, activate it, and you can now get a count of published posts or a list of published post IDs via XML-RPC.