Skip to content
Arun Prakash edited this page Sep 21, 2025 · 15 revisions

πŸš€ Getting Started

Easily integrate WordPress functionalities into your Dart project with the wordpress_client package.

1. Dependency Installation

Add wordpress_client to your project's pubspec.yaml file:

dependencies:
  wordpress_client: ^{latest}

Make sure to check the Package Page for the most recent version.

2. Library Import

Integrate the library into the desired Dart class:

import 'package:wordpress_client/wordpress_client.dart';

3. Client Initialization

Initialize the WordpressClient using either the simple or advanced method. Create it once and reuse the instance across your app.

🟒 Simple Method (REST base)

final baseUrl = Uri.parse('https://example.com/wp-json/wp/v2');
final client = WordpressClient(baseUrl: baseUrl);

🟣 From Site Root (auto‑discovers /wp-json/wp/v2)

final client = WordpressClient.forSite(
  siteUrl: Uri.parse('https://example.com'),
);

πŸ”΅ Advanced Method

final baseUrl = Uri.parse('https://example.com/wp-json/wp/v2');
final client = WordpressClient(
    baseUrl: baseUrl,
    bootstrapper: (bootstrapper) => bootstrapper
        .withStatisticDelegate((baseUrl, requestCount) {
          print('$baseUrl -> $requestCount');
        })
        .withDebugMode(true)
        .withDefaultAuthorization(
          WordpressAuth.appPassword(
            user: 'username',
            appPassword: 'xxxx-xxxx',
          ),
          // or: WordpressAuth.usefulJwt(user: 'username', password: 'password', device: 'device-id')
          // or: WordpressAuth.basicJwt(user: 'username', password: 'password')
        )
        .build(),
);

With custom Dio instance

wordpress_client also offers the flexibility of using a custom Dio instance with the client. This can be achieved by calling WordpressClient.fromDioInstance(...) constructor and by passing the Dio instance via the instance parameter.

That's it! You're now equipped to seamlessly integrate WordPress functionalities into your Dart project using wordpress_client. Happy coding!


πŸ”§ Convenience: Interface Extensions

Each interface exposes an extensions property with useful helpers, keeping the core API clean:

final post = await client.posts.extensions.getById(123);
final bySlug = await client.pages.extensions.findBySlug('about');
final allUsers = await client.users.extensions.listAll(perPage: 100);

🌊 Fluent Queries (No Seed Needed)

Construct list requests with a fluent builder that auto‑seeds the correct request type.

final res = await client.posts.query
  .withPage(1)
  .withPerPage(20)
  .withSearch('hello')
  .withOrder(Order.desc)
  .execute();

// Advanced: mutate the underlying seed
final res2 = await client.posts.query
  .configureSeed((seed) {
    seed.context = RequestContext.view;
  })
  .execute();

// Or access it directly then execute later
final builder = client.posts.query;
builder.seedRequest.context = RequestContext.view;
final res3 = await builder.execute();

Notes:

  • A few interfaces (e.g., revisions/navigation) auto‑seed with placeholder IDsβ€”set them via configureSeed/seedRequest before .execute().
  • There are many fluent helpers (withPage, withPerPage, withSearch, withOrder, withOrderBy, withCategories, withTags, withInclude, withExclude, withStatus, withSlug, withAuthor, etc.). If a field isn’t covered, set it on the seed.
Clone this wiki locally