You may need to flush the REST API cache in order to see the added field. You can do this by adding the following code to your plugin:
This code will flush the REST API cache whenever a post (including a page) is saved or updated, so that the changes to the registered field will appear immediately.
If the field still does not appear after flushing the cache, you may want to check that the REST API request you’re making is for a single page object and not a collection. The field will only be returned when you make a GET request for a single page, for example: wp-json/wp/v2/pages/123.
function flush_rest_api_cache() {
wp_cache_flush();
}
add_action( 'save_post', 'flush_rest_api_cache' );
Related Posts:
- wordpress custom endpoint multiple params
- Continue execution after WP REST API response
- what is the best practice to add new field to an api route
- Building a REST API for your web app exposes primary keys of DB records?
- Cant register rest routs from class instance
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- no_rest_route error on custom routes
- Flatten Responses returned via WP REST API via WP_Error for obfuscation
- Looping through and combining calls to Woocommerce REST API
- get Woocommerce product format json for WP_Query
- Properly process a custom WP REST API request (Authenticate, Authorize + Validate)?
- How to pass and validate nonce in custom REST routes
- Query posts by custom taxonomy slug in WP REST API?
- oneOf JSON Schema validation not properly working for custom post meta value?
- Authenticate + Authorize WP REST API request before built-in WP JSON Schema Payload Validation?
- Custom rest fields not loaded in rest api cpt response
- error_log() output for print_r() appearing on page
- Allow only 1 taxonomy per custom post type [duplicate]
- Do I require the use of nonce?
- Retrieve multiple values passed to a single attribute in a shortcode
- How to change date language without changing the entire site language?
- Save selected item from dropdown menu in a meta box as a metadata value for a custom post type
- OOP Plugin Development. Including external object
- Authenticating to WordPress, using my own authentication two-factor system
- Use composer to load custom classes [closed]
- Why when I instantiate wp_error in a validation method my user registration method stops working?
- Create table in database when activating plugin
- Problem with WordPress Ajax form
- allow user to select pages from dropdown in my plugin
- Using Font Awesome as post thumbnail
- How to set a custom path, for ajax image upload folder in admin?
- admin-ajax.php responding with 0
- custom shortcode will not display the wrapped content
- How to restrict wp generate attachment metadata() to certain intermediate image sizes
- WordPress php filter admin_body_class not working
- Common abstract class for plugins
- Same log message keeps on printing to debug.log file thousand of times
- Is there an equivalent to WP_Error object I can return in the case of a successful REST request?
- Append HTML Using Shortcode
- Create onClick Event to Re-load a Widget
- Accessing the database from a plugin outside of action hooks
- Adding subdomain to home_url for “add_menu_page”
- How to select the contents in the text view textrea in wp_editor?
- How to auto fetch customer details in Woocommerce in checkout page
- Can’t upload image using media_sideload_image
- I want to add custom add to cart link [closed]
- Execute long and heavy processes
- Font Awesome changing default WordPress Font
- Custom plugin settings link doesn’t append current class to menu item when visited? Why?
- Download full html page with CSV export plugin
- Delete taxonomy and delete all post related it
- Usage of call back function of add_meta_box()
- How to set a template with wp_insert_post
- Multiple requests external data api dynamic block gutenberg
- how to save checkbox data for custom setting?
- Can a plugin redirect product page based on IF condition?
- How to Schedule Cronjobs for start of every month and year
- WordPress WP_Query without query GET parameters
- How to clone all WordPress Rest API end points
- Where to copy woocommerce files to in my custom theme to avoid editing the core plugin?
- Removed jQuery script from header.php , any problems?
- How can I get plugin meta data without knowing the plugin folder?
- calling admin-ajax.php from admin-ajax.php
- How does add_option() function enable action hooks to fire right after actiavtion?
- Create plugin with custom page and template caused an error `Call to undefined function get_header()`
- Settings API form – submit with AJAX
- WordPress 5.6 Application Passwords
- Submit remote form to wordpress REST API and save data to custom post type
- Foreach Loop Of Post Types With Nested If Else If Not Completing Process
- WooCommerce REST API AJAX Auth – 401 response
- In a foreach loop, how can I add a meta value if it doesn’t exist?
- Should I use wp_cache in my plugin to make it faster?
- How to import woocommerce custom fields data into another site?
- Add a custom link to each image in WordPress gallery
- How to access this jQuery/AJAX data in a PHP file/WordPress plugin
- post_exists stops working in a scheduled event
- register dependency css and js inside a plugin class
- When I create a new custom post type, it replaces the old post type
- Add .php to end of all WordPress Pages (multisite)
- PHP get_category() function redeclared
- Getting Member Data From WhishList Member on Register
- I’m writing my first plugin and my echo output is showing up on every page of my wordpress installation
- global $post inside plugin query messes up every new post page in wp-admin
- wp_query (or hook) posts by date (id) in array then set post_type
- Chosen Select jquery Not Working in Plugin
- PHP calling function within a class
- Save data of select list after clicking save
- Accessing Variables Used In a Plugin Using PHPStorm + XDebug
- Create and update Custom Cookie based on multiple GET and POST Values for first time visitors?
- Can’t remove menu items added by plugin
- Issues separating my Plugin pages into different files
- How to hide Ads From Certain Categories?
- Custom field fetch error on woocommerce pdf invoice
- Displaying custom meta box value in a custom post page
- Woocommerce Convert existing order to the cart
- how to check elementor is widget is active or loaded
- Create a custom plugin with dynamic child pages listing database records
- Issue with WordPress Plugin Activation Hook and Table Creation
- Too few arguments – wp_login action
- What is different about using admin-ajax.php in an endpoint and just submitting a form from the front end?