Git Product home page Git Product logo

simple-taxonomy-ordering's Introduction

Simple Taxonomy Ordering

Quickly and easily reorder taxonomy terms with an easy to use and intuitive drag and drop interface.

WordPress Versions PHP Versions

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', PHP_INT_MAX, 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 Taxonomies

Alternatively, if you've defined a custom taxonomy 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 notice 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 Taxonomy Ordering' settings page.
  • yikes_simple_taxonomy_ordering_excluded_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.

Issues

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


Originally built with โ™ฅ by YIKES Inc. in Philadelphia, PA.
Now Maintained by Evan Herman in Lancaster, PA.

simple-taxonomy-ordering's People

Contributors

d4mation avatar dependabot[bot] avatar evanherman avatar freddiemixell avatar joemaller avatar jpowersdev avatar lachlanarthur avatar thetracyl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simple-taxonomy-ordering's Issues

Readme โ€” custom post types or custom taxonomies?

It's mentioned in the readme files that

#### Custom Post Types
Alternatively, if you've defined a [custom post type](https://codex.wordpress.org/Post_Types) 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](https://codex.wordpress.org/Function_Reference/register_taxonomy). You can place this line directly after `'hierarchical'`.

Did you mean custom taxonomies instead of custom post types? This plugin can't as far as i understand enable sorting of page-like post types, it only works with taxonomies.

New query crashes get_terms

Hello :)

We have a WordPress site which was using your plugin. Suddenly, functionality using get_terms stopped working.

Here is an errors from the log. I've just x-ed out the taxonomy name.

2016/07/21 13:20:21 [error] 2037#2037: *302 FastCGI sent in stderr: "PHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'term_meta.meta_value ASC' at line 1 for query SELECT  t.term_id, t.name, tt.count, tt.taxonomy FROM wp_terms AS t  INNER JOIN w p_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_termmeta AS term_meta ON t.term_id = term_meta.term_id AND term_meta.meta_key = 'tax_position' WHERE tt.taxonomy IN ('xxxxxx') AND tt.count > 0 term_meta.meta_value ASC [...] after this was just a call stack leadning up to get_terms

There were a couple more, similar, errors.

We were just doing something like get_terms('taxonomy', [and some args here]);.

I deactivated your plugin, and the site started working again.

WordPress version: 4.5.3

Freezes when dragging on large amount of terms

Hi, thank you for the great plugin! However I found some issues when using it on a large number of terms (about 638 items).

  1. At some point it starts to exceed the "max_input_vars" PHP param. It would be great to throw some error or make a notice in the plugin description.

  2. It freezes for a 1-2 seconds after drag-and-drop. I think it would be a good idea to implement up and down buttons with a setTimeout being called. So the order saving starts after the user finishes with it

Bug report: term list shows multiple entries for same term if this term has multiple termmeta values

I use this plugin (version 0.1) in combination with qtranslate-slug which save the translated slugs for terms in the 'termmeta' table. This produces multiple term entries in the term list of my taxonomy.

I found out that this is because of a bug of this plugin. The inner join in the 'yikes_alter_tax_order' function is selecting all termmeta values instead of filtering just the 'tax_position' value for ordering purposes.

Here my suggested fix for this:
yikes-custom-taxonomy-order.php (line 165):
$pieces['join'] .= " INNER JOIN $wpdb->termmeta AS term_meta ON t.term_id = term_meta.term_id AND term_meta.meta_key = 'tax_position'";

I hope you can include that fix in a new release

Not working from an AJAX call (with user taxonomy)

Hi! Thanks for a great plugin with a smooth and non-intrusive UI.

Not sure what exactly has caused this, but automatic sorting of terms didn't work for me if a function containing get_terms is executed from an AJAX call. The taxonomy was manually registered for users.

So the same code (same function was used for an AJAX call and usual template loading) returned terms sorted in a default order (alphabetically by term name) if it was executed via AJAX and correctly sorted by YIKES if it was executed on template load (normally):

$user_positions = get_terms( 'position', array(
    'hide_empty' => false,
    'fields' => 'ids'
    )
);

I changed the code to this and sorting started to work in both cases:

$user_positions = get_terms( 'position', array(
    'hide_empty' => false,
    'fields' => 'ids',
    'meta_key' => 'tax_position',
    'orderby' => 'tax_position'
    )
);

README.md not updated

The README.md file does not reflect latest changes.
The CHANGELOG part should be remove, or pointing to the readme.txt CHANGELOG section, which seems to be kept updated.

Disable custom order on specific places

How can i use my custom order instead of dragndrop order on some places?

$args2 = array(
'orderby' => 'name',
'order' => 'ASC',
'show_count' => 1,
'title_li' => '',
'taxonomy' => 'categoria'
);
wp_list_categories($args2);

Taxonomy ordering not working on AJAX based queries

Hi there!

I'm using this plugin on a site which in some occasions also needs to load taxonomies on an ajax request. However:
https://github.com/yikesinc/yikes-inc-simple-taxonomy-ordering/blob/master/yikes-custom-taxonomy-order.php#L114 uses is_admin(), which unfortunately returns true on front-end ajax requests as well (see https://facetwp.com/is_admin-and-ajax-in-wordpress/)

I could fix this by manually adding the filter in my code, but unfortunately there's no way to reference the only instance of Yikes_Custom_Taxonomy_Order as it's initialized but doesn't exist in the global namespace.

Would it be possible to either (a) have the plugin also work on AJAX requests (although I'm not sure how to exclude admin-based ajax requests in that case) or (b) have a way to reference the class instance, for example make it a Singleton?

Thanks!

Error on line 68 after updating to 2.0.0

Hi,
Noticing an issue after updating Wordpress to 5.1.1 and this Plugin to 2.0.0:

Parse error: syntax error, unexpected 'include' (T_INCLUDE), expecting identifier (T_STRING) in /home/angelu6/public_html/wp-content/plugins/simple-taxonomy-ordering/yikes-custom-taxonomy-order.php on line 68

Looks like the issue is here:

 * Include our files.
	 */
	private function include() {
		include(YIKES_STO_PATH . 'lib/options.php');
	}

Thank you in advance :)

Undefined notice when object_type is not defined

On one WP installation I had a strange error, that object_type for taxonomy was not defined and I would get PHP Notices when trying to enable taxonomy sorting.

To fix it I added additional checks in file options.php line 140
$post_type = ( $tax_object and $tax_object->object_type and sizeof( $tax_object->object_type ) ) ? $tax_object->object_type[0] : 'post'; // setup post type

Can you update repository and publish new version of plugin?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.