Skip to content
This repository has been archived by the owner on Jun 14, 2022. It is now read-only.

A WordPress plugin to assign primary categories to posts and custom post types, for the default category taxonomy.

Notifications You must be signed in to change notification settings

mattradford/mattrad-primary-category

Repository files navigation

Screenshot of Mattrad Primary Category plugin on a post edit screen

Mattrad Primary Categories

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().

Testing

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.

Pre-requisites

  • 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.

Installation

  • 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.

Uninstallation

  • When the plugin is deleted, it will remove any Primary Category metadata that has been set.

Functions

mattrad_get_posts_in_primary_category() accepts two parameters:

  • $term
    • This should be a valid Primary Category term name.
  • $args

mattrad_get_latest_posts_in_primary_category() accepts one parameter:

  • $term
    • This should be a valid Primary Category term name.

Shortcodes

[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.
  • text
    • This defaults to Category: and is prepended to the post's Primary Category.
    • Use text="" to remove or text="Your text here " to set custom text.

To-Do

  • 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)

About

A WordPress plugin to assign primary categories to posts and custom post types, for the default category taxonomy.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages