Install
Upload it under Plugins → Add New Plugin → Upload Plugin, then activate.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/vigetlabs/viget-primary-term/releases/download/v1.0.0/viget-primary-term.zipOn Packagist as viget/viget-primary-term:
composer require viget/viget-primary-term
Viget Primary Term
Lets editors pick a primary term for a post from the block editor's taxonomy panels, e.g. a primary category for a post with several.
Features
- Turn taxonomies on from Settings → Primary Terms, or register them in code with the
vgpt_registered_taxonomiesfilter. Registered taxonomies show on the settings page as locked rows. - A Primary {Term} select appears under the taxonomy's panel once 2+ terms are checked. It lists only the checked terms, including ones just added from the panel.
- The first option shows the fallback, e.g. "Default: Chains › Roller". With no primary term,
get_primary_term()uses the deepest term (hierarchical) or the first by name (flat). - Unchecking the primary term clears it.
- Checks for updates from GitHub releases in the WordPress dashboard.
Block editor only. The classic editor isn't supported.
Installation
Manual
- Download the latest release zip.
- Upload it via Plugins → Add New → Upload Plugin, or extract it to
wp-content/plugins/viget-primary-term/. - Activate the plugin.
Composer
composer require viget/viget-primary-term
Usage
Turn on a taxonomy from Settings → Primary Terms, or in code:
add_filter(
'vgpt_registered_taxonomies',
function ( array $taxonomies ): array {
$taxonomies[] = 'product_category';
return $taxonomies;
}
);
Read a post's primary term:
$term = vgpt()->get_primary_term( $post_id, 'product_category' );
The term ID is stored in post meta as _vgpt_primary_{taxonomy}, registered for the REST API on every post type the taxonomy is attached to. Those post types get custom-fields support, which the REST API needs to include meta.
Auto-Updates
This plugin checks GitHub releases every 12 hours and surfaces updates in Plugins. See includes/class-github-plugin-updater.php. That's incompatible with the wordpress.org plugin directory, which this plugin isn't listed in.
Developer API
Public methods and filters are documented in docs/api.md.
Development
npm install # JS build tooling
npm run start # watch mode
npm run build # production build (build/ is committed)
npm run lint:js # eslint
npm run lint:css # stylelint
composer install # PHPUnit
npm run env:start # wp-env (Docker), on ports 8898/8899
npm test # PHPUnit against real WordPressReleases
1 release. Each count is every asset in that release; expand a row for the breakdown.