These are chat archives for WP-API/node-wpapi

24th
Mar 2017
cAstraea
@cAstraea
Mar 24 2017 16:35
ha :D somehow after googling for the past week I get back here. Been researching lots of things. Does this javascript client levarage the new api introduced in wordpress 4.7 ? I think it's the wp-json/wp/v2 ?
Or is the older one better ?
K Adam White
@kadamwhite
Mar 24 2017 16:39
@cAstraea do not use the v1 API plugin if you can avoid it, its no longer being maintained
cAstraea
@cAstraea
Mar 24 2017 16:39
Just can't for the life of me figure out how to creat posts or users with meta. It should definitely work it's even written in the official documentation. They jus t don't provide an example. https://developer.wordpress.org/rest-api/reference/users/#create-a-user It's right there ... at the bottom meta. And the context for it: meta object Meta fields. Context: view, edit
Couldn't find a single example in the past week of searching
{ "title": "modified", "meta": { "key":"test", "value":"test val" } } this modified the title but nothing hapens to the meta
K Adam White
@kadamwhite
Mar 24 2017 16:39
This library supports the latest 4.7.2 version (tried to post this before, may not have gone through)
cAstraea
@cAstraea
Mar 24 2017 16:39
just mind boggling
K Adam White
@kadamwhite
Mar 24 2017 16:39
Let me send an example of posting with meta...
cAstraea
@cAstraea
Mar 24 2017 16:41
Yes I'm thinking of creating the users directly from the node app so I have like 3 choices that I could find : either levarage the rest api , use a wrapper for wp-cli to do it or g HAM and add them directly to the wp_users and wp_users_meta table which sounds a bit scary
K Adam White
@kadamwhite
Mar 24 2017 16:41
@cAstraea https://github.com/kadamwhite/wp-notebook?files=1 see how the meta is set up with register_rest_meta, and then see how it's being passed in within the JS app source
That request format will work even if you're using a different client or making the requests yourself
cAstraea
@cAstraea
Mar 24 2017 17:00
oh i see you created a custom endpoint for your journal entries using update_post_meta and updating the status
K Adam White
@kadamwhite
Mar 24 2017 17:02
Yeah, register_rest_field is currently the best/only way to reliably expose and set meta without polluting other endpoints
It's documented in the rest API handbook, if you have suggestions on how to better label the section we can try to make it more obvious!
You can use register_rest_field with regular posts and users too, any type of API resource
cAstraea
@cAstraea
Mar 24 2017 17:04
oh that's perfect ! was worried about that. Was thinking there would be issues working with core fields like users
will give it a try tonight :D thx I'm trying to make a integration from chat bot
K Adam White
@kadamwhite
Mar 24 2017 17:11
That sounds like a neat project, good luck!
cAstraea
@cAstraea
Mar 24 2017 17:13
thx