I am a total wp newb and I am struggling to get posts with all their meta(wp_postmeta table) via the WP REST API. http://v2.wp-api.org/reference/posts/
Any guidance is greatly appreciated. Thanks!
I found an easy solution for this. In the current theme - functions.php add the following code:
register_rest_field( 'post', 'metadata', array(
'get_callback' => function ( $data ) {
return get_post_meta( $data['id'], '', '' );
}, ));
It will return posts / post with all it's meta. I.e. http://localhost/rest_api/wp-json/wp/v2/posts or http://localhost/rest_api/wp-json/wp/v2/post/58
post meta will be in "metadata"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With