首页 > 解决方案 > 将 post_category 添加到 PHP XMLRPC

问题描述

我试图弄清楚如何将 post_category 添加到 XMLRPC 使用“PHPXMLRPC”创建的新帖子中。

我有以下代码:

$message = new xmlrpcmsg(
        $function_name, 
        array(
            new xmlrpcval(0, "int"), 
            new xmlrpcval($username, "string"), 
            new xmlrpcval($password, "string"), 
            new xmlrpcval(
                array(
                    "post_type" => new xmlrpcval("post", "string"),
                    "post_status" => new xmlrpcval("publish", "string"),
                    "post_title" => new xmlrpcval($article_title, "string"),
                    "post_category" => new xmlrpcval(array( 'Cars' => 12 ),"int"),
                    "post_author" => new xmlrpcval(1, "int"),
                    "post_content" => new xmlrpcval($new_article, "string")
                    ), 
                "struct"
                )
            )
        );

对于“post_category”,我尝试了很多方法:

                    "post_category" => new xmlrpcval('Cars'),"int"),
                    "post_category" => new xmlrpcval('Cars'),"string"),
                    "post_category" => new xmlrpcval(array( 'Cars' => 12 ),"array"),
                    "post_category" => new xmlrpcval(array( 'Cars' => 12 ),"int"),
                    "post_category" => new xmlrpcval(12),"int"),

以及我能想到的所有其他变化。任何人都可以帮我添加类别(最好通过 NAME,而不是 ID,因为 ID 是未知的)?

标签: phpwordpressxml-rpc

解决方案


推荐阅读