This is a WordPress plugin to assign primary categories to posts and custom post types, for the default category taxonomy only.
Assigned Primary Categories are shown on the WordPress Dashboard, in the post and custom post type indices, via an admin column.
- Show a post's Primary Category with the shortcode
[mr-primary-category]
. - Get posts with a specified Primary Category using the function
mattrad_get_posts_in_primary_category()
. - Or for the latest 10 posts with a specified Primary Category use the speedy function
mattrad_get_latest_posts_in_primary_category()
.
This plugin has been tested with WordPress Theme Test Data and the following themes:
- Twenty Nineteen
- Twenty Twenty
- Twenty Twenty-One
Both Classic Editor and Block Editor are supported.
This plugin has not been tested with WordPress Multisite.
- WordPress 5.8
- PHP 7.3
The plugin is likely to work on earlier versions of WordPress and PHP, but these have not been tested.
- Download the latest release
- Upload the zip file via Plugins -> Add new
- Activate
- Assign Primary Categories via the post edit screen
Or you may install via Composer.
- When the plugin is deleted, it will remove any Primary Category metadata that has been set.
mattrad_get_posts_in_primary_category()
accepts two parameters:
$term
- This should be a valid Primary Category term name.
$args
- This allows the use of WP_Query parameters.
mattrad_get_latest_posts_in_primary_category()
accepts one parameter:
$term
- This should be a valid Primary Category term name.
[mr-primary-category]
accepts two options:
link
- This defaults to
true
and outputs the post's Primary Category as a link to the Category Archive. - Use
link="false"
if you just want the name of the Primary Category to show.
- This defaults to
text
- This defaults to
Category:
and is prepended to the post's Primary Category. - Use
text=""
to remove ortext="Your text here "
to set custom text.
- This defaults to
- Internationalisation
- Support for Tags (post_tags)
- Options page to allow admins to choose post types that primary categories can be applied to
- REST API route
- Activation and Deactivation functions
- Support for custom taxonomies
- Possible: Re-factor to store Primary Categories by ID rather than name
- Possible: Primary Category Archives (could use pre_get_posts to alter existing archives)