Я попытался сделать простую выборку из Wordpress API. В этом случае от ACF Fields.
С кодом:
Я получил ответ. Но если я попытаюсь
добавить
$ {post.acf.address}
нет данных Но почему, кто-нибудь, кто может мне помочь?
Вот код:
function getPosts() {
fetch(
"https://localhost/wp-json/wp/v2/tourplan?per_page=100"
)
.then(res => res.json())
.then(data => {
let output = '<h2 class="mb-4">Posts</h2>';
data.forEach(function(post) {
output += `
<div class="card card-body mb-3">
<h2>${post.acf.location}</h3>
<h3>${post.acf.programmname}</h3>
<p>${post.acf.datum}</p>
<p>${post.acf.beginn}</p>
</div>
`;
console.log(data);
});
document.getElementById("output").innerHTML = output;
});
}
Это ответ json, если вы вызываете URL выборки в браузере.
[
{
"id": 5692,
"date": "2019-05-08T14:41:15",
"date_gmt": "2019-05-08T12:41:15",
"guid": {
"rendered": "https://localhost/?post_type=tourplan&p=5692"
},
"modified": "2019-05-08T14:41:15",
"modified_gmt": "2019-05-08T12:41:15",
"slug": "münchen",
"status": "publish",
"type": "tourplan",
"link": "https://localhost/Tourplan/münchen/",
"title": {
"rendered": "München"
},
"content": {
"rendered": "",
"protected": false
},
"template": "",
"authorName": "wtced",
"acf": {
"plz": "81825",
"location": "Wirtshaus",
"programmname": "\"Programmname\"",
"datum": "20190913",
"einlass": "18:00",
"beginn": "20:00",
"ticketlink": "https://localhost/hxanh/",
"ausverkauft": false,
"vvk": "Veranstalter: Testverein e.V.",
"zusatzfeld": "",
"maps": {
"address": "Feldstraße 35, 81825 München, Deutschland",
"lat": "48.386076050384",
"lng": "11.348405060504"
}
}
]