getButterfly
Resume

NAVIGATION

ATTRIBUTION

getButterfly
Dublin, Ireland

All Content Copyright ©2019
getButterfly

WordPress Primary Category

WordPress Primary Category

Set a primary category for your (custom) posts and query them in your template using native WordPress queries.

This plugin has been coded as part of a hiring interview. Now that the interview is out of the way, here’s the plugin in all its glory. It’s also hosted on GitHub.

Assumptions

  • Custom post types use the native category taxonomy – 'taxonomies' => array('category')

Further improvements

  • Dynamically show/hide _builtin post types (default to show).
  • Dynamically show/hide non-public (non-publicly queryable) post types (default to hide).
  • Add better communication between the Primary Category metabox and the Category metabox (anchor links or JavaScript appending).
  • Add more contextual help to both the metabox and the plugin’s settings.
  • Add/extend functionality to allow for primary taxonomies by getting all taxonomies attached to a custom post and adding the same functionality as for categories.
  • Migrate jQuery code to native JavaScript for zero-dependencies (even if jQuery is loaded by default in the post editing screen).

Context

Depending on the publisher’s implementation and use of Yoast SEO plugin (which already has this functionality), a query can be built using the plugin’s code without adding any metaboxes or custom plugin settings. For this plugin, though, I have created the solution 100% from scratch.

Compatibility and security

  • The plugin does not use the new PHP 7 array notation, in order to be backwards compatible with older PHP versions (note the PHP requirement in the readme.txt header).
  • The plugin is translation-ready (WordPress plugin repository) by using the same name for the plugin folder, the main plugin file and the text domain.
  • The plugin is licensed as GPLv3.
  • The plugin is not accessible directly by browsing the plugin’s directory.

Photo by Sanwal Deen on Unsplash.

Added by Ciprian on Monday, June 11, 2018 in Blog

Do you want better SEO? More traffic? More conversions? More growth? We help companies exponentially grow their traffic and conversions, while outranking their competitors. With more than 10 years of experience, we’ve learned what is valuable to our clients.
SEO Dublin | SEO Malta

My Battle Tested Recommendations

Jetpack
Dreamhost
WordPress.com
CodeCanyon
SEMrush

Disclaimer: These recommendations contain affiliate links.


Privacy Policy