【问题标题】:XMLRPC & MetaWeblog, how can i create a page, create a post, and attach the page to this postXMLRPC 和 MetaWeblog,我如何创建页面、创建帖子并将页面附加到此帖子
【发布时间】:2011-12-23 10:10:01
【问题描述】:

我想为我的Wordpress博客创建自己的自定义发布界面,我这样做的原因是因为我发布了多篇文章,有时每天100-150篇不等,我想简化发布一篇文章的过程,比如批量发布文章。

我做了研究,发现 Wordpress XMLRPCMetaWeblog API 是我需要的。

所以我试了一下,我成功地使用这个代码在我的博客上发布了一篇文章:

<?php
    include("../wp-includes/class-IXR.php");
    $client = new IXR_Client('http://www.example.com/xmlrpc.php');

    $content['title'] = 'Test Draft Entry using MetaWeblog API';
    $content['description'] = '<p>Hello World!</p>';
    if (!$client->query('metaWeblog.newPost','', 'admin',’password’, $content, false)) {
        die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
    }
    echo $client->getResponse();    
?>

但是对于我在 Wordpress 博客中创建的每篇文章都需要几个步骤:

第一步:新建一个Background类型为Youtube的Background,并输入这个背景的Youtube ID。

第 2 步:添加新帖子并将之前发布的背景附加到此帖子。

第 3 步:在自定义字段部分输入一个名为artist_id 的自定义字段,并为该帖子添加摘录,发布帖子。

所以,每篇文章需要 3 个步骤。所以我的问题是,如何使用 XMLRPC 来执行这些操作?

【问题讨论】:

    标签: wordpress xml-rpc metaweblog


    【解决方案1】:

    要添加摘录,请使用

    $content['mt_excerpt'] = 'Your post excerpt';
    

    对于自定义字段使用

    $content['custom_fields'] = array(
        array( 'key' => 'artist_id', 'value' => '777' ),
        array( 'key' => 'background', 'value' => 'background_value' )
      );
    

    背景和 youtube 元框很可能会添加自定义帖子元。您可以从 db 或源代码中找到它们的密钥,并在上面的代码中使用它。

    【讨论】:

    • 如何发布新的后台帖子?我正在使用来自主题森林的村庄模板,该模板具有背景帖子类型。我需要找到一种方法来发布这个新背景
    猜你喜欢
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 2022-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多