Last active
August 30, 2015 14:00
-
-
Save sunriseweb/7250fc300c897e4e39d6 to your computer and use it in GitHub Desktop.
Add filter to Custom Taxonomy Order NE plugin so that taxonomies list in customtaxorder_wp_get_object_terms_order_filter function can be modified.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* customtaxorder_wp_get_object_terms_order_filter | |
* wp_get_object_terms is used to sort in wp_get_object_terms and wp_get_post_terms functions. | |
* get_terms is used in wp_list_categories and get_terms functions. | |
* get_the_terms is used in the the_tags function. | |
* tag_cloud_sort is used in the wp_tag_cloud and wp_generate_tag_cloud functions (but then the get_terms filter here does nothing). | |
* Default sorting is by name (according to the codex). | |
* | |
*/ | |
function customtaxorder_wp_get_object_terms_order_filter( $terms ) { | |
global $customtaxorder_settings; | |
$options = $customtaxorder_settings; | |
if ( empty($terms) || !is_array($terms) ) { | |
return $terms; // only work with an array of terms | |
} | |
foreach ($terms as $term) { | |
if ( is_object($term) && isset( $term->taxonomy ) ) { | |
$taxonomy = $term->taxonomy; | |
} else { | |
return $terms; // not an array with objects | |
} | |
break; // just the first one :) | |
} | |
if ( !isset ( $options[$taxonomy] ) ) { | |
$options[$taxonomy] = 0; // default if not set in options yet | |
} | |
if ( $options[$taxonomy] == 1 && !isset($_GET['orderby']) ) { | |
if (current_filter() == 'get_terms' ) { | |
$customtaxorder_exclude_taxonomies = array('post_tag', 'product_tag'); | |
if ( in_array($taxonomy, apply_filters( 'customtaxorder_exclude_taxonomies', $customtaxorder_exclude_taxonomies )) ) { | |
// no filtering so the test in wp_generate_tag_cloud() works out right for us | |
// filtering will happen in the tag_cloud_sort filter sometime later | |
// post_tag = default tags | |
// product_tag = woocommerce product tags | |
return $terms; | |
} | |
} | |
usort($terms, 'customtax_cmp'); | |
return $terms; | |
} | |
return $terms; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment