Tuesday, June 21, 2022
HomeWordPress Developmentwp question - How can I return solely IDs from the `posts`...

wp question – How can I return solely IDs from the `posts` REST endpoint?


I’ve the next code:

const FORMS = doc.querySelectorAll(".search-form");

FORMS.forEach((type) => {
    const INPUT  = type.querySelector(".search-form__input");
    const BUTTON = type.querySelector(".search-form__button");

    BUTTON.addEventListener("click on", (e) => {
        e.preventDefault();

        wp.apiRequest({
            path: "wp/v2/posts",
            information: {
                search: INPUT.worth,
            },
        }).then(information => {
            console.log(information);
        });

    }, { passive: false });
});

WP_Query permits you to specify "fields" => "ids" to return solely the put up IDs. I solely want the IDs from this request, so to be able to reduce down on database queries, I would like to use this identical setting to the request. Is there a method to specify this within the REST API? I’ve tried setting fields: "ids", within the information property, however that does not have any impact.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments