使用Node.js创建具有自定义字段的WordPress页面

时间:2018-10-30 14:59:39

标签: node.js wordpress

我一直在尝试使用自定义字段创建WordPress页面。下面的代码只是添加了一个自定义字段,但方式错误。字段名称是y,值也是。

    client.newPost({
    type: "page", 
    title: "a Page from Node.js", 
        content: "This page was created sending remotely post from 
    Node.js.....",
        status: "publish",
        pagetemplate: "template1.php",
        customFields: {
            "test":"yes"
        },
   }, function( error, data ) {
    console.log( "Post sent! The server replied with the following:\n" );
    console.log( arguments );
    console.log("\n");
});

我尝试使用:custom_fields,customFields,字段

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

file_list = [open(file, 'r') for file in files] 
    num_files = len(file_list) 
    wordFreq = {}  
    for i, f in enumerate(file_list): 
        for line in f: 
            for word in line.lower().split():
                if not word in wordFreq:
                    wordFreq[word] = [0 for _ in range(num_files)]
                wordFreq[word][i] += 1

自定义字段的正确格式为:

client.newPost({
    type: "page", 
    title: "a Page from Node.js", 
        content: "This page was created sending remotely post from 
    Node.js.....",
        status: "publish",
        pagetemplate: "template1.php",
        customFields: [
            { key: "test", value: "yes" }
        ],
   }, function( error, data ) {
    console.log( "Post sent! The server replied with the following:\n" );
    console.log( arguments );
    console.log("\n");
});

代替:

customFields: [
    { key: "test", value: "yes" }
]

在本地测试:

  • WordPress 4.9.8
  • node-wordpress 1.4.1