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?
- Application password header not checked in REST API
- Custom rest fields not loaded in rest api cpt response
- Delete a WordPress transient from a shortcode on Page/Post update
- Plugin CSS not enqueing
- Create onClick Event to Re-load a Widget
- Swapping wp_dropdown_categories function with wp_category_checklist
- Accessing the database from a plugin outside of action hooks
- Adding subdomain to home_url for “add_menu_page”
- How to show phpinfo() only in a new tab?
- How to find error in my code when the error message is pointing to WP core file?
- How to select the contents in the text view textrea in wp_editor?
- How to access global variable $menu inside a class function
- Hide categories that are not used in the post type
- Automated Cart Update With Alert Box Each Time
- How can I remove a function that has been added to wordpress with add_filter?
- PHP Fatal error: Uncaught mysqli_sql_exception: Table doesn’t exist in wordpress/wp-includes/wp-db.php
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- How to sanitize any integer input field in wordpress?
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- WordPress ajax doesn’t display object method on jQuery .change() function
- Custom user login page by creating a plugin
- Singelton class does not work, multiple initialization on page reload
- Saving an array of dynamic repeater data as post_meta
- Woocommerce hook run after an Order been created through REST API
- filter default query to show just selected level of child pages in wordpress
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- WordPress wpform plugin submit and get multiple checked value from checkbox [closed]
- How to upload a file to a folder named after the user_id via plugin
- Reprinting tags with all attributes
- How to show single category archive
- Woocommerce api: create product with images – bad request
- Use custom post type for a store locator
- developing a wordpress plugin, have a few PHP Woocommerce related coding questions
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Improve page speed loading using CDN and async or defer attribute
- How do I programmatically set a user as spam in BuddyPress? [closed]
- wp_remote_get() returns 403 while file_get_contents() does not
- How to use $_GET function WordPress backend
- Whitelisting items from custom options page
- Add_menu_page not displaying the menu in class based plugin
- How to call plugin function per site in a multisite?
- Update results, Before deleting the related category [closed]
- How to make my custom widget appear within WordPress widgets? Plugin development
- Script to browser problem PHP
- adjust section according to country?
- How to auto fetch customer details in Woocommerce in checkout page
- Can’t upload image using media_sideload_image
- Store a default value for a transient on plugin activation
- Are nonces in WP REST API optional by default?
- Adding widgets to my plugin page instead of WordPress dashboard
- WP CRON duplicate wp_insert_post with has < and > tag
- How wp-cron can run in background if PHP is single threaded?
- How to insert data into database using wp cron job
- How to send Ajax request from my plugin in admin dashboard?
- I want to add custom add to cart link [closed]
- Options API get_option() and update_option() Not Correctly Updating or Returning
- Execute long and heavy processes
- how to save selected option in variable for rest api category filter
- wp_head function not outputting
- wp query foreach deleting record returning only first or last item
- Extend PHP regex to cover “srcset” and “style” attributes
- Adding function to Genesis genesis_header [closed]
- AJAX success response is not working but it’s saving my changes
- Access Child Class of Plugin Main Class Instance
- PHP > Scheduled Tasks > Sending daily email with dynamic API variables
- How to make own crop image function for WordPress plugin
- WordPress Custom field Colors
- Best practice for show data to one specific user?
- How can I hide that I Use WordPress (with W3 Total Cache)
- how to update and display an option without reloading the page
- Font Awesome changing default WordPress Font
- Saving plugin settings – ERROR: options page not found
- Custom plugin settings link doesn’t append current class to menu item when visited? Why?
- class_exists returns different values [closed]
- “Undefined index” error when saving empty array with checkboxes
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Download full html page with CSV export plugin
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Asynchronous multiple requests 401 Unauthorized
- JSON REST API WordPress only showing first 10 categories
- How to use html inside a functions.php code?
- Custom array from a query only write the last row of the query
- How to hook code to show after the_content?
- Plugin Generate Unexpected output during activation