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?
- Change Password Hint
- Create a new user using WP REST API and declare meta object
- How to use a frontend URL with a Plugin
- register_rest_route regex option for base64 or alternate
- WordPress template_include filter not working properly
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- How to display a value from a radio button in the options menu in wordpress
- How to generate HMAC-SHA1 signature to use with WP REST API and OAuth1
- How to call function at the bottom of post using plugin?
- WP add_action factory
- Swapping wp_dropdown_categories function with wp_category_checklist
- How to show phpinfo() only in a new tab?
- How can I remove a function that has been added to wordpress with add_filter?
- wp_remote_get() returns 403 while file_get_contents() does not
- How to use $_GET function WordPress backend
- how to save selected option in variable for rest api category filter
- Extend PHP regex to cover “srcset” and “style” attributes
- How can I hide that I Use WordPress (with W3 Total Cache)
- Saving plugin settings – ERROR: options page not found
- class_exists returns different values [closed]
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Asynchronous multiple requests 401 Unauthorized
- Custom array from a query only write the last row of the query
- Using data sent via AJAX in multiple functions on a WP plugin
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- What does -> mean in WordPress?
- Change product_base programmatically
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- Permission callback to check if user has application password
- How to add the sidebar to all the pages except the home page? [closed]
- Custom meta box values are not getting saved for my custom post type
- Simple WordPress endpoint route doesn’t work
- Is it possible to create new user from external form using REST API?
- Plugin development and composer
- WC_Customer delete function returns error
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- Custom route and query
- Set default Database Storage Engine when creating tables with plugins?
- REST API works in browser and via AJAX but fails via cURL
- custom post type with role Vendor
- Can I remove or edit an include() from a function with a filter?
- Call to undefined function error in plugin
- How do I make this Metabox show current DB value?
- Execute Jquery when a specific page in my plugin is loading
- Get category id when SEO URL is turned on
- Using ACF Relationship field to set post type to draft or published status
- WordPress api post image raw data without being blank in media library
- WordPress can’t use ZipArchive
- How to extend SelectControl with data from my theme
- Only the first image uploads
- How do i post data to url with fields?
- Trying to use a variable to set image width
- How can i avoid duplicate same post in wp?
- How do I disable cache for a certain page?
- How to check if plugin update process completed in wordpress?
- How to identify which php file a plugin is using on page load?
- dashboard widget form not submit mails
- register_setting not save checkbox
- using filter and hook inside class
- Showing how many times is plugin activated or deactivated
- How does one make a URL return dynamic JSON with custom Content Type?
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- Require advice handling a URL redirect from a Third Party. URL Params need to populate and then forward to payment
- Priority call methods – PHPMailer->addAddress(NULL)
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- How to properly escape in ternary operators – Wp Coding Standards?
- Add Admin Option w/ Anonymous Function
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- How to send logs to plugin owner for a plugin?
- Force CSV download with template_redirect
- How to use foreach and if statement within array of arrays?
- Custom post type single page return to listing page
- WordPress rewrite question
- Using Nonce for my Form
- Create new folder and upload files to custom folder via wp_handle_upload
- How to edit the default database of WordPress [closed]
- Cookie not created in AJAX request
- How to automatically convert images to WebP on WordPress?
- Check user last login date
- Transate plugin with js & wp_localize_script
- WP Custom tables query
- Login user into magento using wordpress account
- ajax problems on loading page [closed]
- Customize create table SQL statement in any WordPress plugin
- Accessing Correct Database to Create REST API Endpoint