You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过WordPress API选择Elementor自定义模板自动创建博客文章?

解决方案:Elementor自定义模板集成Power Automate + SharePoint

问题1:在Power Automate中使用Elementor自定义模板

WordPress REST API默认不直接展示Elementor自定义模板选项,需通过设置文章的**自定义字段(post meta)**关联模板:

  1. 从WordPress后台进入自定义模板编辑页,从URL中提取模板ID(如编辑URL为wp-admin/post.php?post=123&action=elementor,则ID为123)。
  2. 在Power Automate的WordPress「Create Post」动作中,打开Advanced options,添加自定义字段:
    • 键(Key):_elementor_template
    • 值(Value):你的自定义模板ID(如123)
  3. 完成后创建的文章会自动应用指定的Elementor自定义模板。

若需通过模板名称动态获取ID,可在WordPress中添加自定义REST端点:

add_action('rest_api_init', function () {
    register_rest_route('custom/v1', '/elementor-template/(?P<name>[a-zA-Z0-9-]+)', [
        'methods' => 'GET',
        'callback' => function ($data) {
            $template = get_posts([
                'post_type' => 'elementor_library',
                'name' => $data['name'],
                'posts_per_page' => 1
            ]);
            return $template ? ['id' => $template[0]->ID] : new WP_Error('not_found', 'Template not found', ['status' => 404]);
        }
    ]);
});

在Power Automate中先调用该端点获取ID,再传入创建文章的动作即可。

问题2:自动填充模板的特定文本框

推荐两种可靠实现方式:

方式1:Elementor动态标签(优先选择)

  1. 编辑Elementor自定义模板时,将需填充的文本控件设置为动态标签:点击控件的动态标签图标 → 选择「Post Meta」→ 定义自定义字段名(如sp_title、sp_content)。
  2. 在Power Automate创建文章时,添加对应自定义字段:
    • 键:sp_title,值:SharePoint列表的标题字段
    • 键:sp_content,值:SharePoint列表的内容字段
  3. 文章创建后,Elementor会自动读取这些字段并填充到对应控件中。

方式2:直接更新Elementor控件内容

若需精准控制,可在创建文章后调用Elementor API修改控件内容:

  1. 创建文章并获取文章ID,调用GET /wp-json/elementor/v1/documents/{post_id}获取模板控件数据。
  2. 修改目标控件的settings.content值为SharePoint字段内容(需提前获取控件ID,如text-editor-1,可从Elementor编辑界面的开发者工具中查看)。
  3. 调用PUT /wp-json/elementor/v1/documents/{post_id}提交修改后的控件数据,示例请求体:
{
  "data": {
    "widgets": {
      "text-editor-1": {
        "settings": {
          "content": "<p>从SharePoint获取的内容</p>"
        }
      }
    }
  }
}

注意事项

  • 确保Power Automate使用的WordPress账号拥有创建文章、编辑自定义字段的权限。
  • 自定义REST端点需配置合适的权限控制,避免未授权访问。

内容的提问来源于stack exchange,提问作者Henrique Weber Soeiro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 05:45:10