There are a few reasons why calling an API twice on the same page might fail the second time in WordPress:
The API call may be cached by WordPress or your browser, so the second call is returning the same cached data. To resolve this, you can try disabling caching or using a plugin that allows you to clear the cache on the page where the API call is being made.
The API may have a rate limit in place, which means that there is a limit to the number of requests that can be made within a certain time period. If you are making multiple calls to the same API on the same page, you may be exceeding this limit and causing the second call to fail. To resolve this, you can try reducing the number of calls or spreading them out over a longer period of time.
The API may require authentication, such as an API key, to be passed with each call. If you are not passing the correct authentication information with the second call, it may be failing. To resolve this, you can try passing the correct authentication information with each call.
The server where your WordPress installation is running might have some restrictions or settings that don’t allow multiple requests to the same API. You can check with your hosting provider or server administrator to see if there are any such restrictions.
Third-party plugin or theme issue:
The issue could be caused by a plugin or theme that is conflicting with the API call. Try disabling all non-essential plugins and switch to a default theme to see if this resolves the issue.
In general, it’s a good idea to check the API documentation and see if there are any guidelines or best practices for making multiple calls on the same page. Also, you can use tools like Fiddler, Charles, or the browser dev tools to inspect the network request and see what is causing the failure.
Last modified: January 23, 2023