需要帮助以通过WP API更新ACF中的值

发布于 2025-02-10 14:13:08 字数 1510 浏览 2 评论 0原文

我正在尝试使用WordPress API通过PHP中的WordPress ACF插件中的“行”功能更新一个项目。

我想更改的价值是“星期一”,

这是终点的JSON:

{
    "id": 765,
    "acf": {
        "contact": "2150",
        "sched": [
            {
                "field_611218a978d03": "Monday",
                "field_6112197d78d04": "00:00:00",
                "field_6112199f78d05": "17:00:00"
            }
        ],
    },
}

我可以将“ 2150”的值更改为“ 2151”,

'body' => array(
        'acf' => array (
            'contact' => "2151",
        ),
    )

但我无法更改“星期一”的值,我'VE已经尝试了以下内容:

'body' => array(
        'acf' => array (
            'sched' => array ( array ( "field_611218a978d03" => "Tuesday")
        )
    )

以及:

'body' => array(
        'acf' => array (
            'sched' => array ( 
                  [0] => array( "field_611218a978d03" => "Tuesday")
        )
    )
)

我一直在搜索,并且似乎没有与此特定问题有关的答案。我已经陷入困境了几天。任何帮助都将不胜感激!

编辑: 要回答cbroe,这是我正在使用的代码:

$api_response = wp_remote_post( 'domain.com/wp-json/wp/v2/person/765', array(    
    'headers' => array('Authorization' => 'Basic ' . base64_encode( 'user:pass' )),
    'body' => array(
        'acf' => array (
            'contact' => '2150',
            'sched' => array ( array ( "field_611218a978d03" => "Tuesday")
        ),
    )
    ));

    $body = json_decode( $api_response['body'],true);

I'm trying to update an item particularly with the "rows" feature in WordPress ACF plugin via PHP using Wordpress API.

The value I'm looking to change is "Monday"

Here's the json from the endpoint:

{
    "id": 765,
    "acf": {
        "contact": "2150",
        "sched": [
            {
                "field_611218a978d03": "Monday",
                "field_6112197d78d04": "00:00:00",
                "field_6112199f78d05": "17:00:00"
            }
        ],
    },
}

I can change the value of "2150" to "2151" with the following:

'body' => array(
        'acf' => array (
            'contact' => "2151",
        ),
    )

But I can't change the value of "Monday", I've already tried the following:

'body' => array(
        'acf' => array (
            'sched' => array ( array ( "field_611218a978d03" => "Tuesday")
        )
    )

As well as:

'body' => array(
        'acf' => array (
            'sched' => array ( 
                  [0] => array( "field_611218a978d03" => "Tuesday")
        )
    )
)

I've been searching and there seems to be no answer pertaining to this specific problem. I've been stumped for days now. Any help would sincerely be appreciated!

Edit:
To answer CBroe this is the code I'm working with:

$api_response = wp_remote_post( 'domain.com/wp-json/wp/v2/person/765', array(    
    'headers' => array('Authorization' => 'Basic ' . base64_encode( 'user:pass' )),
    'body' => array(
        'acf' => array (
            'contact' => '2150',
            'sched' => array ( array ( "field_611218a978d03" => "Tuesday")
        ),
    )
    ));

    $body = json_decode( $api_response['body'],true);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文