rest api – search

  • Unknown's avatar

    Dear,

    https://developer.wordpress.com/docs/api/1.1/post/sites/site/search/

    Dose search api above require paid user ?
    And bearer token is necessary ?
    I want to search posts with search text. But it seems not to work.

    Please show some examples using js fetch. I struggled to use it, especially request query parameter

    Thank you

    WP.com: Yes
    Jetpack: No
    Correct account: Yes

    The blog I need help with is: (visible only to logged in users)

  • Unknown's avatar

    auto answer below not work

    {error: ‘Bad Request’, message: ‘Incorrect JSON Formatting’}

    [code lang="javascript"]<br /> fetch('https://public-api.wordpress.com/rest/v1.1/sites/{site}/search', {<br /> headers: {<br /> 'Authorization': 'Bearer {bearer token}'<br /> },<br /> method: 'POST',<br /> body: JSON.stringify({<br /> search: 'your search text'<br /> })<br /> })<br /> .then(response =&gt; response.json())<br /> .then(data =&gt; {<br /> // Handle the search results here<br /> console.log(data);<br /> })<br /> .catch(error =&gt; {<br /> // Handle any errors here<br /> console.error(error);<br /> });<br /> [/code]

  • The topic ‘rest api – search’ is closed to new replies.