wp.types().type( 'landing_page' ).embed()
wp.media().file()
in RN (if that even matters). I've tried passing both path and File with no success. When I pass path the WP REST API respond with rest_upload_no_data
and if I pass a File Object I get the following message File is empty. Please upload something more substantial....
. I've tried using a simple fetch
request with FormData and it works fine. Am I doing something wrong or there is some kind of limitation when node-wpapi is used in RN? Thank you!
Hey there, I'm new to node-wpapi and like it but I can't find an answer to a supposedly easy question: Is it possible to reduce the WP API response to only needed fields with node-wpapi? The WP REST API Doc features the _fields query param (see https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_fields), but in the node-wpapi doc I can't find related information. Any help appreciated, thanks in advance!
I guess I found it out on my own by playing around and reading code on Github. For anyone asking him/herself the same question I did: You can use WPRequest.param() method as in this example:
wpapi.pages().param('_fields', 'id,slug,title,parent').
The wordpress API will return a JSON with all pages in it but for each page only the parameters id, slug, title and parent are listed. So far it tested it with WPReuqest objects returned by wpapi.root(), wpapi.pages().orderby().order() and wpapi.post() and it seems to work as I intended, reducing the JSON download size and thus the loading time.
wp.productsAPI = wp.registerRoute("wp/v2", "/wp-manga/");
wp.productsAPI().create({
title: 'Your Post Title2',
content: 'Your post content2',
status: 'publish'
}).then(function(post) {
console.log("post", post, "post");
return wp.media().file('prueba.png').create({
title: 'Amazing featured image',
post: post.id
})
}).then(function(media) {
// Set the new media record as the post's featured media
return wp().posts().id(post.id).update({
featured_media: media.id
});
});
Hey, what to do? I never got that error before, can't fetch or update any posts, I changed nothing, yesterday worked normally and idk what to do.
node_modules\superagent\lib\request-base.js:342
this._header[field.toLowerCase()] = val;
^
TypeError: Cannot set property 'authorization' of undefined
Code:
this.wp.series()
.param("status", "any")
.then(async (series) => {
let result = await getOnlyNeededInfo(series);
resolve(result);
})
.catch((err) => {
this.handleError(err);
resolve(false);
});
const posts = () => wp.posts().perPage( 100 );
const WPAPI = require ('wpapi');
var wpdev = new WPAPI ({
endpoint: '..../wp-json',
username: '...',
password: '...'
});
wpdev.acfAPI = wpdev.registerRoute("acf/v3", "/posts/(?P<id>[\\d]+)/?(?P<field>[\\w\\-\\_]+)?", {
params: [ 'main_sidebar' ]
});
main();
async function main () {
let resp = await wpdev.acfAPI().id(62542).field("main_sidebar").get();
console.log(resp);
console.log(JSON.stringify(resp));
}
If I updated the actual post instead, like this:
await wpdev.posts().id(62542).update({
// updates
})
It seems there's a way to reach the ACF field? i.e.
// updates
data: { "acf": { "main_sidebar": "contents here" } }
That seems to be better... At least it doesn't throw an error. But nothing happens when I run this code:
let result = await wpdev.posts().id(117925).auth().update({
data: {
"acf": {
"main_sidebar": "test"
}
},
status: 'publish'
});
console.log(result);
The sidebar doesn't update. Is the structure of my request wrong?
It was really simple in the end, but that's how it always is, isn't it? lol
Working code for anyone else looking for the same solution:
let result = await wpdev.posts().id(117925).auth().update({
"fields": {
"main_sidebar": "test"
},
status: 'publish'
});
console.log(result);
Should be able to replace "main_sidebar" with any custom field set by acf