Skip to content
Advertisement

wp_remote_get and url parameters

I’m trying to use an API with wp_remote_get which requires pagination.

Currently, my WordPress plugin calls the API the following way

JavaScript

Now, if I change the URL from /products to /products?page_size=5&page=2, which works fine in Postman and other programs, i am not getting a response. Why is that? I checked the API documentation of wp_remote_get but am not figuring it out.

Advertisement

Answer

Typically you use curl command to GET the response but I would recommend you to use Guzzle PHP HTTP client to make your calls if you are making multiple of them.

You will have to compser install Guzzle.

JavaScript

I am expecting that the autoloader class is loaded.

Once installed and you can use it as follows.

JavaScript

You can change the $url and $payload for other queries.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement