Receiving JSON POST data in PHP is a common scenario I come across when building custom WordPress API’s. If you’re working with JSON API’s powered by PHP you may find that $_POST is not working with JSON, and you may be seeing a broken response of Array or NULL.

Processing $_POST data with application/javascript headers

To receive a request with a content-type of application/javascript in PHP you’ll need to use the following:

$data = json_decode( file_get_contents( 'php://input' ), true );

This is really for my own reference/editor integration, but hopefully it’s helpful to you as well!

Meet the Author

Kevin Leary, Boston WordPress Developer of 10 Years

I'm a freelance web developer and WordPress consultant in Boston, MA with 13 years of experience building websites and applications. View a portfolio of my work or request an estimate for your next project.