I have a PHP script running in WordPress, that uses a
WP_Query to get the posts from one of my subdomains and return it as a JSON string. The script only receives the post data if I call it using the correct subdomain.
For example, if I go to
news.example.com/api/news.php, the JSON prints correctly, but if I go to
www.example.com/api/news.php it only prints an empty array.
How can I call a single script that will get data from a subdomain, even if I call it using the main domain? Or even better, if I call it from any subdomain?