Skip to content
Branch: master
Clone or download
Latest commit 749c2a1 Feb 28, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
example Update Feb 26, 2019
test Implemented Wordpress JSON schema as class. Feb 11, 2019
.gitignore init Feb 11, 2019
.metadata init Feb 11, 2019 -- homepage url update Feb 28, 2019
LICENSE -- doc update Feb 13, 2019
pubspec.yaml -- release 0.1.4 Feb 28, 2019

Flutter Wordpress

This library uses WordPress REST API V2 to provide a way for your application to interact with your WordPress website.



For authentication and usage of administrator level REST APIs, you need to use either of the two popular authentication plugins in your WordPress site:

  1. Application Passwords
  2. JWT Authentication for WP REST API (recommended)

Getting Started

1. Import library

import 'package:flutter_wordpress/flutter_wordpress.dart' as wp;

2. Instantiate WordPress class

wp.WordPress wordPress;

// adminName and adminKey is needed only for admin level APIs
wordPress = wp.WordPress(
  baseUrl: 'http://localhost',
  authenticator: wp.WordPressAuthenticator.JWT,
  adminName: '', 
  adminKey: '',

3. Authenticate User

Future<wp.User> response = wordPress.authenticateUser(
  username: 'ChiefEditor',
  password: 'chiefeditor@123',

response.then((user) {
}).catchError((err) {
  print('Failed to fetch user: $err');

4. Fetch Posts

Future<List<wp.Post>> posts = wordPress.fetchPosts(
  params: wp.ParamsPostList(
    context: wp.WordPressContext.view,
    pageNum: 1,
    perPage: 20,
    order: wp.Order.desc,
  fetchAuthor: true,
  fetchFeaturedMedia: true,
  fetchComments: true,

5. Fetch Users

Future<List<wp.User>> users = wordPress.fetchUsers(
  params: wp.ParamsUserList(
    context: wp.WordPressContext.view,
    pageNum: 1,
    perPage: 30,
    order: wp.Order.asc,
    role: wp.UserRole.subscriber,

6. Fetch Comments

Future<List<wp.Comment>> comments = wordPress.fetchComments(
  params: wp.ParamsCommentList(
    context: wp.WordPressContext.view,
    pageNum: 1,
    perPage: 30,
    includePostIDs: [1],

7. Create Post

void createPost(wp.User user) {
  final post = wordPress.createPost(
    post: new wp.Post(
      title: 'First post as a Chief Editor',
      content: 'Blah! blah! blah!',
      excerpt: 'Discussion about blah!',
      pingStatus: wp.PostPingStatus.closed,
      status: wp.PostPageStatus.publish,
      format: wp.PostFormat.standard,
      sticky: true,

  post.then((p) {
    print('Post created successfully with ID: ${}');
    postComment(user, p);
  }).catchError((err) {
    print('Failed to create post: $err');

8. Post Comment

void postComment(wp.User user, wp.Post post) {
  final comment = wordPress.createComment(
    comment: new wp.Comment(
      content: "First!",
      parent: 0,

  comment.then((c) {
    print('Comment successfully posted with ID: ${}');
  }).catchError((err) {
    print('Failed to comment: $err');

Future Work

  1. Implementing OAuth 2.0 authentication.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.