A modern C++23 client library for the WordPress REST API.
Provides type-safe entity classes and a generic CRUD client so you can create, read, update, and delete WordPress content — posts, pages, categories, and media — directly from C++ code.
- Full CRUD — create, retrieve, list, update, and destroy any entity type
- Type-safe entities —
Wp::Post,Wp::Page,Wp::Category,Wp::Media - Fluent query builder — filter, paginate, and sort collection requests with method chaining
- Media upload — multipart file upload to the
/mediaendpoint - HTTPS — TLS support via OpenSSL
- Header-only API client —
Api.hpprequires no separate compilation - No external package manager — dependencies are bundled as single-header files
#include "Api.hpp"
#include "Post.hpp"
int main()
{
Wp::Api api({
.url = "https://your-site.com",
.user = "wpUser",
.password = "application-password"
});
// Create a post
auto post = std::make_unique<Wp::Post>();
post->setTitle("Hello from C++");
post->setContent(Wp::Item::TextType::RAW, "This post was created by WordpressAPI.");
post->setStatus(Wp::Item::Status::PRIVATE);
api.create(post);
// Retrieve it back
auto fetched = api.retrieve<Wp::Post>(post->getId());
// Update it
fetched->setTitle("Hello from C++ (edited)");
api.update(fetched);
// Delete it permanently
api.destroy(fetched, /*force=*/true);
return 0;
}Wp::Post::Query q;
q.search("release notes")
.status({Wp::Item::Status::PUBLISH})
.perPage(5)
.page(1);
auto posts = api.list(q);
for (auto const& p : posts)
{
// p->getId(), p->getTitle(), p->getLink(), …
}auto media = api.uploadMedia("/path/to/photo.jpg", "image/jpeg");
// media->getSourceUrl(), media->getMimeType(), …| Class | WordPress endpoint | Inherits |
|---|---|---|
Wp::Post |
/wp-json/wp/v2/posts |
ContentItem → Item → Entity |
Wp::Page |
/wp-json/wp/v2/pages |
ContentItem → Item → Entity |
Wp::Category |
/wp-json/wp/v2/categories |
Entity |
Wp::Media |
/wp-json/wp/v2/media |
Item → Entity |
Every entity exposes a ::Query builder for use with Wp::Api::list().
| Tool | Minimum version |
|---|---|
| CMake | 3.31 |
| C++ compiler | C++23 (GCC 13+ / Clang 17+) |
| OpenSSL | any recent version |
cmake -S . -B build
cmake --build buildThe static library is written to build/lib/libWordpressAPI.a.
add_subdirectory(WordpressAPI/api)
target_link_libraries(your_target PRIVATE WordpressAPI)The test suite contains live integration tests against a real WordPress instance. They require a valid test/credentials.hpp (not included in the repository).
Copy the placeholder that is checked in and fill it in:
// test/credentials.hpp
#include "Api.hpp"
const Wp::Api::Credentials wpCreds =
{
.url = "https://your-site.com",
.user = "wpUser",
.password = "application-password",
};Tell git to keep your local credentials private:
git update-index --skip-worktree test/credentials.hppBuild and run:
cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failureIndividual test suites can be run by name:
ctest --test-dir build -R ConnectionTest
ctest --test-dir build -R PostTest
ctest --test-dir build -R PageTest
ctest --test-dir build -R CategoryTest
ctest --test-dir build -R MediaTestapi/
├── src/ # Library headers and source files
│ ├── Api.hpp # Header-only CRUD client (main entry point)
│ ├── Entity.* # Abstract base class for all entities
│ ├── Item.* # Timestamped entity base (posts, pages, media)
│ ├── ContentItem.* # Content-bearing base (posts, pages)
│ ├── Post.* # WordPress post entity
│ ├── Page.* # WordPress page entity
│ ├── Category.* # WordPress category entity
│ └── Media.* # WordPress media attachment entity
└── ext/ # Bundled third-party headers
├── httplib/ # cpp-httplib
└── json/ # nlohmann/json
test/ # Integration test suite (Google Test)
doc/ # UML class diagram and sample API responses
WordpressAPI bundles the following excellent single-header libraries — no package manager required.
| Library | Version | Author | License |
|---|---|---|---|
| cpp-httplib | 0.29.0 | Yuji Hirose | MIT |
| nlohmann/json | 3.12.0 | Niels Lohmann | MIT |
The test suite uses Google Test (v1.14.0), fetched automatically by CMake at build time.
This project is released under the MIT License.