Thanks @sallyCJ for fixing my error !
Here’s some examples for WP-API backbone JS client. It may help others :
Fetch post of a certain author and category :
var filteredPosts = new wp.api.collections.Posts();
authorsPosts.fetch({ data: { author: currentUserId, categories: 42 } }).then( posts => {
for(const post of posts){
//do stuff with each post
}
} );
Update a post :
var post = new wp.api.models.Post( {
id: idOfThePostYouWantToUpdate,
title: newTitle,
content: newContent,
status: newStatus,
categories: [ 42 ],
tags: [ 50 ]
});
post.save();
Related Posts:
- Check if user can in javascript
- Rest API invalid nonce with Backbone Client
- Setting/unsetting terms using the Backbone JavaScript client
- How to render WP Rest-API Endpoints in a React.js Theme with Woocommerce
- Access checks with custom REST endpoints and backbone
- Nonce retrieved from the REST API is invalid and different from nonce generated in wp_localize_script
- Implementing Isomorphic JavaScript (React JS) in WordPress?
- Show only images and videos in a wp.media window
- REST API: Backbone and custom endpoint
- Open media frame and select an attachment
- WordPress Rest API
- Gutenberg custom block plugin with custom image sizes
- Get loading state of wp data selector
- Switch to the library tab in the media uploader
- What type of template are WP media-modal’s templates?
- WP REST – video and audio players
- Headless WordPress: How to authenticate front end requests?
- Post to WordPress using REST API from external site
- Updata Metadata WP Rest API
- How to handle malformed response from WP REST API?
- Rest API authentication issue when called from fetch request in bundle.js
- Get HTTP response code on non-2xx apiFetch request
- Extending wp JavaScript base class to make a post request to a custom REST endpoint
- WP REST API Post Status Using JavaScript
- How to retrieve a value from an input field in a media view template
- How to transform a legacy widget into a block
- Use the backbone.js client to save custom post type meta
- Authentication with the Rest API when using an External Application
- Get Block Attributes in JSON REST API
- Checks when fetching data from multiple REST API endpoints in Gutenberg
- Is there a media_upload_tabs-similar filter to add tabs to the simple/featured image picker?
- Search for a keyword across post types in a Gutenberg component
- Using apiFetch for retrieving post data in Gutenberg
- Get terms of a taxonomy using useSelect
- Return ‘X-WP-Total’ from headers in response
- Retrieving data about comments and likes
- how to use nimble-API and Display data?
- Why does my array sort order changes when I pass it to JS using WP_REST_Response?
- Rest API and how to deal with it in server side
- URL issue retrieving Custom Post Types using Backbone JS API
- Insert HTML markup to page content from the Media Frame modal
- [Vue warn]: Error in render: “TypeError: Cannot read property ‘wp:featuredmedia’ of undefined – REST API
- Update block once an API request returns with a value
- Get user in rest API endpoint
- How to improve WP-Rest atrocious response time?
- I would like to retrive JSON value and display it in wordpress page or widget
- Connecting a wordpress site to an AngularJS APP
- WP-API + JS Backbone client – how to update post meta
- Combining results from WP-API using AngularJS
- WordPress REST API response is empty in browser and script, but not in Postman
- WP REST API – “rest_user_cannot_view” ONLY on specific users
- Get Comment Text via REST API
- How to submit a button automatically after every scheduled hours?
- How to make a word underline in Markdown
- JQuery – $ is not defined
- Is it possible to sandbox JavaScript running in the browser?
- What is the convention in JSON for empty vs. null?
- Generating random whole numbers in JavaScript in a specific range?
- How to extract extension from filename string in Javascript?
- keep getting “? Something is already running on port 3000” when I do npm start on react app
- React Context vs React Redux, when should I use each one?
- Regular expression : match either of two conditions?
- Difference between innerText, innerHTML and value?
- Uncaught TypeError: data.push is not a function
- Length of a JavaScript object
- I want to remove double quotes from a String
- Calculating median – javascript
- Vue is not defined
- How to remove all listeners in an element?
- How do I check if an object has a key in JavaScript?
- How to write inside a DIV box with javascript
- use Lodash to sort array of object by value
- Chrome/jQuery Uncaught RangeError: Maximum call stack size exceeded
- How to get unique values in an array
- Set scroll position
- .filter is not a function
- Function overloading in Javascript – Best practices
- Wait until flag=true
- momentJS date string add 5 days
- When is a CDATA section necessary within a script tag?
- How to get scrollbar position with Javascript?
- where is create-react-app webpack config and files?
- How to wrap the content of the main tinyMCE editor with extra tags
- Javascript not working?
- Add Item to Custom TinyMCE Menu
- WordPress Rest API only returns content when posttype has editor capability
- Logout user and delete cookies from the client side?
- How can I get my Calculate Contact Form 7 field to update with jQuery? [closed]
- Update a post based on results from GET request to another server
- Cannot use characters ” in jQuery script in WordPress
- How to install cool javascript feature in WordPress?
- Normal for scripts to be loaded after body tag?
- Allow REST API Endpoint to specific user and hide from public
- JS inside modal doesn’t work
- How to Get Post Meta in .Js File [duplicate]
- Immediate (e.g. without DOMContentLoaded) JS not working
- Script not working in post content
- Javascript 2 elements dependent onclick .toggle [closed]
- Metabox conditionals depending on post format and template in Gutenberg
- Javascript functions not running