Answer the question
In order to leave comments, you need to log in
How to correctly collect json for sending via API?
Good afternoon!
It is necessary to send via wp_remote_request () to send json of the form,
I collect it like this
for ($i = 1; $i <= 5; $i++) {
$alt_url = get_post_meta($post_id, 'alt_page_'.$i, true);
if ($alt_url) {
// TODO: добавить массив
$alternative_pages_array[] = array(
array(
'id' => $alt_url,
'active' => true
),
);
}
}
$current_url = get_permalink($post_id);
$new_array = array(
'base_id' => $current_url,
'urls' => $alternative_pages_array
);
$args_urls = array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'headers' => array(
'content-type' => 'application/json',
'x-access-key' => $access_key,
),
'body' => json_encode($new_array, JSON_UNESCAPED_SLASHES),
);
"base_id":"http://site.ru/base/",
"urls":[
[{
"id":"http://site.ru/page1-2",
"active":true
}],
[{
"id":"http://site.ru/page2-2",
"active":true
}],
[{
"id":"http://site.ru/page3-2",
"active":true
}],
[{
"id":"http://site.ru/page4-2",
"active":true
}],
[{
"id":"http://site.ru/page5-2",
"active":true
}]
]
}
Answer the question
In order to leave comments, you need to log in
$alternative_pages_array[] = array(
'id' => $alt_url,
'active' => true
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question