![]() For example, if you wanted to add a custom field called url to the post type post, you would use the following code. The key parameters required are the object type and meta key, and then an array of specific arguments. This is done using the register_meta function. However, in order to use a custom field, you have to register it first. This is possible by passing an object of key value pairs to the meta property of the model you’re working with. ![]() The WordPress REST API allows you to create or update custom fields when creating or updating data. You can read more about this in the MetaData API documentation on. Beyond posts, WordPress also supports metadata on other data types, such as comments and users. If you’ve ever worked with the add_post_meta, update_post_meta, and get_post_meta functions, you’ve accessing these custom fields. Under the hood, these custom fields are stored in the post meta table as a set of key value pairs attached to the post by the post ID. These fields are often used on custom post types to store additional pieces of data that are specific to that post type. And each function is called when the corresponding button is clicked.īesides the default fields that exist on a post, WordPress also allows you to add and manage custom fields also known as metadata. ![]() There are individual functions to handle each of these actions. Listing posts uses the post collection and creating and updating and deleting posts uses the post model. The plugin has a PHP file which handles the Admin menu and forms and a JavaScript file which interacts with the REST API using the Backbone.js client. It also has a form that allows you to add a new post by entering the title and content fields and clicking the Add button, update a post by entering a post id, title, and content and clicking the Update button, and delete a post by entering the post id and clicking the Delete button. And it uses the REST API to load the posts from the sites and display them in the top text area. To review this plugin adds a new admin sub menu page to the Tools top level menu. This tutorial builds on the code examples shared in the last tutorial, you can download the plugin that was created in that tutorial from this URL, and use it as the basis for this tutorial. If you’ve never interacted with the WordPress REST API before, I recommend watching the Interacting with WordPress REST API tutorial first, and then coming back here. You’ll also learn how to use the REST API testing tool to test your REST API routes and endpoints. ![]() You will learn how to create or update custom fields while creating or updating posts, and how to authenticate with the REST API using application passwords. In this tutorial, you’re going to learn a few more ways to interact with the WordPress REST API. Hey there, and welcome to Learn WordPress. ![]()
0 Comments
Leave a Reply. |