How to receive HTTP POST in WP?

Easy! You have a couple of options to do so.

The easiest one, but less safe, is to create a brand new PHP file in the root folder of WordPress. Let’s say we will call it get_post.php and add WordPress functionality to it.

Like so:

<?php 
    require_once('wp-load.php'); // add wordpress functionality
    $post = $_POST;

    if ( $something ) // security check
    update_post_meta( $post['post_id'], 'post_data', $post );
?>

The API link will be yourdomain.com/get_posts.php

Another option is to create a brand new page template inside of your template directory. And create a page using that template within your WordPress dashboard.

<?php 
    /* Template Name: Api Template */ 

    if ( ! defined( ‘ABSPATH’ ) ) {
        exit;
    }

    $post = $_POST;

    update_post_meta( $post['post_id'], 'post_data', $post );
?>

The API link will be: yourdomain.com/newly-created-page-permalink.

Leave a Comment