Closed GarvMaggu closed 4 years ago
Here is my code:
createPost() async {
wp.User user;
Future<wp.User> response = wordPress.authenticateUser(
username: '*****',
password: '***********',
);
await response.then((value) {
user = value;
});
print('-------------');
print(response);
final post = await wordPress.createPost(
post: wp.Post(
title: 'Hello',
content: 'Example content',
excerpt: 'Example excerpt',
authorID: user.id,
commentStatus: wp.PostCommentStatus.closed,
pingStatus: wp.PostPingStatus.closed,
status: wp.PostPageStatus.publish,
format: wp.PostFormat.standard,
featuredMedia: 'https://upload.wikimedia.org/wikipedia/en/e/e6/Example_of_a_Shader.png',
),
);
You can't upload media that way. You'd have to upload the file using the media
endpoint from the REST API (which the flutter_wordpress does not support) and use the newly uploaded media ID when creating your new oost.
You can't upload media that way. You'd have to upload the file using the
media
endpoint from the REST API (which the flutter_wordpress does not support) and use the newly uploaded media ID when creating your new oost.
Ohh, okay. But then why there are two different properties for featuredMedia in createPost function? featuredMedia -> String (Source URL of the image) featuredMediaID -.> Integer (Media ID from Wordpress Media Library)
What is the function of featuredMedia property?
featuredMedia
is a Post property that contains the media path (if any) when you fetch a Post, while featuredMediaID
contains the media ID; but when you create a new Post featuredMedia
is completely discarded and only featuredMediaID
is actually sent to the API.
featuredMedia
is a Post property that contains the media path (if any) when you fetch a Post, whilefeaturedMediaID
contains the media ID; but when you create a new PostfeaturedMedia
is completely discarded and onlyfeaturedMediaID
is actually sent to the API.
Ohh, perfect, completely understood it now. Thanks a lot for clearing it out.
You can add these lines from this commit to upload files to WordPress Media Library: https://github.com/dreamsoftin/flutter_wordpress/pull/45/commits/7ba21f6124817e8cb40f968582e06a9084fb831c
When creating a post, featuredMedia is not getting uploaded to Wordpress nor it is setting as a featuredImage for the post, I tried passing many random .jpg and .png URLs from the internet but none of them worked. However, title, content, excerpt, and rest everything is working fine and a post is being created but without the Featured Media