Configuration
WP-Node provides a flexible configuration system to support both single-site and multi-site WordPress environments. It also allows customization of Taxonomy, Post Type, and Post Status via CLI.
Global Configurationโ
At a minimum, WP-Node requires a staticAssetsPath
configuration. If using WordPress in multi-site mode, additional fields are needed.
๐งฉ Single-Site Configurationโ
{
"staticAssetsPath": "public"
}
๐งฉ Multi-Site Configurationโ
{
"staticAssetsPath": "public",
"multisite": {
"enabled": true,
"defaultBlogId": 1,
"defaultSiteId": 1
}
}
Once initialized, WP-Node will enrich this configuration internally. You can inspect the full config via:
const context = await Application.getContext();
console.log(context.config.config);
โ ๏ธ Note: WP-Node Core does not interact with or modify media files such as images or uploads on the file system. Its focus is on interacting with the WordPress database.
staticAssetsPath
setting is still required because WordPress stores metadata (e.g.,_wp_attached_file
inpostmeta
) that references file paths. WP-Node uses this metadata to work with attachments, but it does not read, write, or serve the actual media files.
Taxonomy Configurationโ
WP-Node CLI can generate configuration files for custom taxonomies. These configurations support features such as hierarchy, and capability settings.
๐ ๏ธ Create a Custom Taxonomy (with Hierarchy Enabled)โ
npx @rnaga/wp-node-cli -- config taxonomy -h yes
โ CLI Output Exampleโ
โ Enter new taxonomy name (ASCII and underscore only): ยท custom_category
_wp/config/taxonomy.json created successfully.
_wp/config/taxonomy.d.ts created successfully.
๐ฅ Using Custom Taxonomy in Codeโ
You can retrieve terms from the newly defined taxonomy via:
const post = await context.utils.post.get(1);
const terms = post.terms("custom_category");
โ๏ธ Updating the Taxonomy Configurationโ
Edit _wp/config/taxonomy.json
to customize its behavior, e.g., toggle hierarchical, disable showUi, or set custom capabilities:
{
"custom_category": {
"hierarchical": false,
"showUi": false,
"capabilities": {
"manage_terms": "manage_terms",
"assign_terms": "assign_terms",
"edit_terms": "edit_terms",
"delete_terms": "delete_terms"
}
}
}
Post Type Configurationโ
To define a custom post type, use the CLI with the -n
flag:
npx @rnaga/wp-node-cli -- config postType -n custom_post
This generates both the JSON and TypeScript type definition in _wp/config
.
Post Status Configurationโ
Similarly, you can define a custom post status:
npx @rnaga/wp-node-cli -- config postStatus -n custom_type