I have the following code:
const FORMS = document.querySelectorAll(".search-form");
FORMS.forEach((form) => {
const INPUT = form.querySelector(".search-form__input");
const BUTTON = form.querySelector(".search-form__button");
BUTTON.addEventListener("click", (e) => {
e.preventDefault();
wp.apiRequest({
path: "wp/v2/posts",
data: {
search: INPUT.value,
},
}).then(data => {
console.log(data);
});
}, { passive: false });
});
WP_Query
allows you to specify "fields" => "ids"
to return only the post IDs. I only need the IDs from this request, so in order to cut down on database queries, I'd like to apply this same setting to the request. Is there a way to specify this in the REST API? I've tried setting fields: "ids",
in the data
property, but that doesn't have any effect.
_fields : "id"
work?(?my-endpoint=posts)
and useget_posts( array('fields' => 'ids') );
?