【问题标题】:Create WordPress page with custom fields using Node.js使用 Node.js 创建带有自定义字段的 WordPress 页面
【发布时间】:2018-11-16 05:02:00
【问题描述】:

我一直在尝试使用自定义字段创建 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、fields

【问题讨论】:

    标签: node.js wordpress


    【解决方案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" }
    ]
    

    代替:

    customFields: {
        "test":"yes"
    }
    

    在本地测试:

    • WordPress 4.9.8
    • node-wordpress 1.4.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多