最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论