Create a custom post with custom post-metadata with WP API

I'm using WP API to insert a custom post in Wordpress. The custom post is property. What I now need to do is assign that post a metadata (DB table wp_postmeta)

At first I thought It was going to be easy like (I'm using Symfony Http class here):

Http::withBasicAuth($user, $password)-post({$endpoint}/property, [
    'date' = now(),
    'status'  = 'publish',
    'title' = 'Test',
    //etc...
    'meta' = [
        'custom_metadata' = 1234 
    ]
]);

The custom property post gets created but the meta does not.

I did register my custom post in functions.php like so:

//Add property listing capability
function my_custom_post_type_rest_support() {

    global $wp_post_types;
    $post_type_name = 'property';

    if( isset( $wp_post_types[ $post_type_name ] ) ) {
        $wp_post_types[$post_type_name]-show_in_rest = true;
    }
}
add_action( 'init', 'my_custom_post_type_rest_support', 25 );

And I do get listings and I can filter specific property posts.

I cannot add metadata to the post and I cannot figure out how to do it, and I have a hard time the documentation.

Topic wp-api custom-post-types Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.