=== UXL Primary Term ===
Contributors: uxl
Tags: primary category, category, taxonomy, post terms, quick edit
Requires at least: 6.3
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Choose a primary category (or other taxonomy term) for posts, and show just that term with the Post Terms block.

== Description ==

When a post belongs to more than one category, UXL Primary Term lets you mark one of them as the primary category. It works with categories, tags and other taxonomies, including custom taxonomies on custom post types.

* **Block editor** – a "Primary Category" (or "Primary Tag", etc.) select appears under the taxonomy panel once two or more terms are selected. It lists only the selected terms.
* **Quick Edit** – the same select appears in Quick Edit on the posts list, and updates as you tick categories or type tags.
* **Only when it makes sense** – a primary term can only be set when a post has two or more terms. If a post drops to a single term, or the primary term is removed, the primary setting is cleared automatically.
* **Post Terms block** – a "Show primary term only" option on the Post Terms block (Categories, Tags or any taxonomy) shows a single term. Use it in templates and Query Loops.
* **Posts list** – the primary term is shown in bold in the Categories, Tags and other taxonomy columns.
* **Permalinks** – if your permalinks include `%category%`, the primary category is used.

= What is shown when no primary term is set? =

When "Show primary term only" is on and a post has no primary term, the block shows the post's first term instead. Terms are ordered by popularity (the number of posts in the term), then alphabetically, and the first one is shown.

= For developers =

`uxl_get_primary_term( $taxonomy = 'category', $post = null )` returns the primary `WP_Term`, or `null` if none is set.

`uxl_get_display_term( $taxonomy = 'category', $post = null )` returns the primary term, or the fallback term described above.

The primary term ID is stored in post meta `_uxl_primary_term_{taxonomy}` and is available in the REST API.

Filters:

* `uxl_primary_term_taxonomies` – the taxonomies that support a primary term. Defaults to all taxonomies (categories, tags and custom taxonomies) with an admin UI that are shown in the REST API, except post formats. Remove a taxonomy from the array to turn the feature off for it.
* `uxl_primary_term_fallback_term` – the term used when no primary term is set.
* `uxl_primary_term_use_in_permalink` – return false to stop the primary category being used in permalinks.

== Installation ==

1. Upload the `uxl-primary-term` folder to `/wp-content/plugins/`, or install it from the Plugins screen.
2. Activate the plugin.
3. Edit a post with two or more categories and choose the primary category in the sidebar or in Quick Edit.

== Frequently Asked Questions ==

= Why can't I see the primary category select? =

It only appears when two or more categories are selected for the post.

= Does the editor preview of the Post Terms block show only the primary term? =

No. In the post editor, the block lists all of the post's terms. In the template editor, it shows the taxonomy name as a placeholder, e.g. CATEGORIES. The single term is only shown on the front end.

= Does it work with the Classic Editor? =

Quick Edit works everywhere. The post edit screen select is for the block editor.

== Changelog ==

= 1.0.0 =
* Initial release.
