question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a guide for "how to work with meta"

See original GitHub issue

Hi, i tried to update post meta, when i created posts, but nothing happened It’s possible with node-wpapi? wp.song().create({ title: '1', content: 'Your post content', status: 'publish', meta: {key: 'youtube', value: '12'}, }).then(function( response ) { console.log( response.id ); })

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
dimadincommented, Oct 25, 2017

When you create/update post, you pass meta object, for example:

wpapi.posts().create( {
	title: 'Your Title',
	content: ' Your content',
	status: 'publish',
	meta: {
		custom_meta_key: 'something'
	}
} ).then( function( response ) {
	// whatever
} );

On the server side, you must use register_meta(). If you are using custom post type, the post type must have custom-fields support (see documentation for $args['supports'] of register_post_type(). That is documented for REST API.

But if you are using meta with custom role, your role should also have edit_post_meta (and delete_post_meta if you are deleting) capability. See code for WP_REST_Meta_Fields::update_meta_value() and WP_REST_Meta_Fields::delete_meta_value(). I haven’t seen that this is documented anywhere so I figured it out during debugging.

3reactions
dmdbcommented, Jun 15, 2018

Messed with the same problem, being total noob in wordpress infrastructure. Solved by putting

register_meta('post', 'duration', [
  'type' => 'integer',
  'description' => 'duration',
  'single' => true,
  'show_in_rest' => true,
]);

into functions.php of theme. This unlocked me:

meta: { duration: 123 }
Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Learning on Workplace and how do I use it? - Facebook
You may need to click See All below Groups section first. Click More, then click Learning. Click Start a Guide and add a...
Read more >
The Workplace New User Guide
You can also add a short bio to tell your coworkers a little more about ... Check out this guide for more tips...
Read more >
How to Use Meta Business Suite - Social Media Examiner
From the All Tools menu, select File Manager. Then click the Create Folder button to get started. Give the folder a name and...
Read more >
META General User Guide
how to use the search screens, see the Searching Curriculum section of this guide. Profile Management. The first time you log in, you...
Read more >
Getting started with Meta Quest 2
If you're new to Meta Quest, a Meta account is required to use your device, apps and the app store. You'll be asked...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found