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?
- addEventListener vs onclick
- window.onload vs document.onload
- Fetch: POST JSON data
- JavaScript hide/show element
- Copy array by value
- How do I empty an array in JavaScript?
- What’s the difference between event.stopPropagation and event.preventDefault?
- ReferenceError: fetch is not defined
- What is “assert” in JavaScript?
- How does the data-toggle attribute work? (What’s its API?)
- How to import image (.svg, .png ) in a React Component
- How do I embed PHP code in JavaScript?
- Make javascript alert Yes/No Instead of Ok/Cancel
- How to validate date with format “mm/dd/yyyy” in JavaScript?
- How to handle the `onKeyPress` event in ReactJS?
- ES6: Create Strings using Template Literals – Freecodecamp
- Jest TypeError: Path must be a string. Received undefined
- How do I convert an integer to binary in JavaScript?
- Convert CSV data into JSON format using Javascript
- Can not solve: Geocode was not successful for the following reason: OVER_QUERY_LIMIT
- ReactJS – .JS vs .JSX
- How to convert date to timestamp?
- ReactJS: Maximum update depth exceeded error
- React, Uncaught ReferenceError: ReactDOM is not defined
- Finding the max value of an attribute in an array of objects
- How to initialize an array’s length in JavaScript?
- How to set text color for my d3 chart title?
- Defining a HTML template to append using JQuery
- How do I bind to list of checkbox values with AngularJS?
- Wildcard string comparison in Javascript
- Hiding WordPress REST API v2 endpoints from public viewing
- What does l10n.js do in WordPress 3.1? And how do I remove it?
- How to add javascript just before the closing body tag in the footer of WordPress
- wp_localize_script with boolean and init
- WordPress loads whole jQuery UI library
- What is the Javascript event for an item being added to the cart in Woocommerce?
- Can the index.asset.php file be used with the enqueue_block_editor_assets action?
- How do I fetch all comments per post via WP REST API?
- Adding inline JavaScript encoding issue
- a child theme not de-registering a patent javascript file
- WP REST API and Access-Control-Allow-Origin
- Using javascript on my site to create nested tabs
- Get style and script file versions and use them while writing a cache manifest file
- Javascript working on jsfiddle but not wordpress site?
- Drodown list return issue
- Put dynamic Javascript in header after doing operations
- Adding javascript blocks to a single file and adding it to the header