Skip to content

danielschwab/yikes-inc-simple-taxonomy-ordering

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YIKES Inc. Simple Taxonomy Ordering

This plugin allows you to easily re-order taxonomy terms via drag and drop functionality, using the new term meta included in WordPress v4.4.

Installation

  1. Install and activate the plugin
  2. If you need to enable term sorting on default WordPress taxonomies, please see below.
  3. If you would like to enable taxonomy term sorting on custom post type taxonomies, please see below.
  4. Once enabled, you can drag & drop re-order your taxonomy terms. Whenever 'get_terms()' is used to display your terms, they will display in the order you've set.

Usage

Default WordPress Taxonomies

After installing and activating the plugin, you have two options. You can enable drag & drop on any of the default taxonomies. To enable drag & drop sorting on default WordPress taxonomies, you'll want to assign the tax_position parameter to the register_post_type call.

The easiest way to do so, is to use the following snippet.

/*
* Enable drag & drop sorting on default WordPress taxonomies (ie: categories) - (page/post)
*/
add_filter( 'register_taxonomy_args' , 'add_tax_position_support', 9999, 3 );
function add_tax_position_support( $args, $taxonomy, $object_type ) {
	if( 'category' == $taxonomy ) { // Change the name of the taxonomy you want to enable drag&drop sort on
		$args['tax_position'] = true;
	}
	return $args;
}

Custom Post Types

Alternatively, if you've defined a custom post type that you'd like to allow drag & drop sorting on, you'll want to pass in a tax_position parameter to the $args array inside of register_taxonomy. You can place this line directly after 'hierarchical'.

Example Snippet

'tax_position' => true,

Front End

On the front end of the site, anywhere get_terms() is used to query a set of taxonomy terms, they will be returned in the order of their position on the taxonomy list. No additional steps need to be taken on on your end.

Example

Admin Taxonomy Sorting Usage

Frequently Asked Questions

Can I make default WordPress taxonomies drag and drop sortable?

Indeed, you can! You'll have to assign the 'tax_position' parameter to the taxonomy. You can do this easily, using the following sample code snippet.

You'll note in the code snippet, the taxonomy we are using is 'category' - but you can change this value to suit your needs.

I have a custom post type, but it won't let me drag and drop sort it's taxonomies. How come?

As mentioned above, the taxonomies need to have the parameter 'tax_position' => true assigned to it. If the taxonomy is missing this parameter the items won't actually be sortable. For an example of how to implement it, please see the following code snippet.

How does the taxonomy know what order to remain in?

With the release of WordPress 4.4 came taxonomy meta data, which gets stored inside of the wp_termmeta table in the database. Each taxonomy is assigned an integer value related to it's position on the taxonomy list.

Filters

  • yikes_simple_taxonomy_ordering_capabilities - Filter to adjust who can access the 'Simple Tax. Ordering' settings page.
  • yikes_simple_taxonomy_ordering_ignored_taxonomies - Filter to add additional taxonomies or remove default taxonomies. Items in this array will not be displayed in the dropdown on the settings page, and thus cannot have drag and drop sorting enabled. (defaults: 'nav_menu', 'link_category', 'post_format')

Issues

If you're running into any issues, we would love to hear about it. Please head over to the Simple Taxonomy Orering Issue Tracker and create a new issue.

Changes

v0.1 - December 11th, 2015

  • Initial Release

===========

Built with by YIKES Inc. in Philadelphia, PA

About

Drag and drop order support for taxonomies, using the new termmeta table.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 91.8%
  • JavaScript 8.2%