Version Description
- 2022-04-27
- Improve ordering nested sub-terms.
Download this release
Release Info
Developer | mpol |
Plugin | Custom Taxonomy Order NE |
Version | 3.4.1 |
Comparing to | |
See all releases |
Code changes from version 3.4.0 to 3.4.1
- customtaxorder.php +59 -8
- readme.txt +5 -1
customtaxorder.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Custom Taxonomy Order
|
4 |
Plugin URI: https://wordpress.org/plugins/custom-taxonomy-order-ne/
|
5 |
Description: Allows for the ordering of categories and custom taxonomy terms through a simple drag-and-drop interface.
|
6 |
-
Version: 3.4.
|
7 |
Author: Marcel Pol
|
8 |
Author URI: https://timelord.nl/
|
9 |
License: GPLv2 or later
|
@@ -39,7 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
39 |
|
40 |
|
41 |
// Plugin Version
|
42 |
-
define('CUSTOMTAXORDER_VER', '3.4.
|
43 |
|
44 |
|
45 |
/*
|
@@ -180,6 +180,14 @@ add_filter('get_terms_defaults', 'customtaxorder_get_terms_defaults', 10, 2);
|
|
180 |
function customtaxorder_wp_get_object_terms_order_filter( $terms ) {
|
181 |
$options = customtaxorder_get_settings();
|
182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
$terms_old_order = $terms;
|
184 |
|
185 |
if ( empty($terms) || ! is_array($terms) ) {
|
@@ -216,24 +224,67 @@ function customtaxorder_wp_get_object_terms_order_filter( $terms ) {
|
|
216 |
$ancestors = get_ancestors( $term->term_id, $term->taxonomy, 'taxonomy' );
|
217 |
if ( is_array($ancestors) && ! empty($ancestors) ) {
|
218 |
$toplevel_ancestor_id = array_pop( $ancestors );
|
219 |
-
$
|
220 |
-
if ( is_object($
|
221 |
-
$front_of_float = (string) $
|
|
|
222 |
$rear_of_float = '';
|
|
|
223 |
foreach ( $ancestors as $ancestor_id ) {
|
224 |
$ancestor_term = get_term($ancestor_id, $term->taxonomy);
|
225 |
if ( is_object($ancestor_term) && isset($ancestor_term->term_order) ) {
|
226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
}
|
228 |
}
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
$term->term_order = (float) ( $front_of_float . '.' . $rear_of_float );
|
231 |
}
|
232 |
}
|
233 |
}
|
234 |
}
|
235 |
usort($terms, 'customtax_cmp');
|
236 |
-
|
237 |
$terms_new_order = $terms;
|
238 |
/*
|
239 |
* Fires after term array has been ordered with usort.
|
3 |
Plugin Name: Custom Taxonomy Order
|
4 |
Plugin URI: https://wordpress.org/plugins/custom-taxonomy-order-ne/
|
5 |
Description: Allows for the ordering of categories and custom taxonomy terms through a simple drag-and-drop interface.
|
6 |
+
Version: 3.4.1
|
7 |
Author: Marcel Pol
|
8 |
Author URI: https://timelord.nl/
|
9 |
License: GPLv2 or later
|
39 |
|
40 |
|
41 |
// Plugin Version
|
42 |
+
define('CUSTOMTAXORDER_VER', '3.4.1');
|
43 |
|
44 |
|
45 |
/*
|
180 |
function customtaxorder_wp_get_object_terms_order_filter( $terms ) {
|
181 |
$options = customtaxorder_get_settings();
|
182 |
|
183 |
+
/*if ( is_admin() ) {
|
184 |
+
$doing_ajax = wp_doing_ajax();
|
185 |
+
if ( $doing_ajax && $_POST['action'] === 'get-tagcloud' ) {
|
186 |
+
var_dump($terms);
|
187 |
+
return $terms;
|
188 |
+
}
|
189 |
+
}*/
|
190 |
+
|
191 |
$terms_old_order = $terms;
|
192 |
|
193 |
if ( empty($terms) || ! is_array($terms) ) {
|
224 |
$ancestors = get_ancestors( $term->term_id, $term->taxonomy, 'taxonomy' );
|
225 |
if ( is_array($ancestors) && ! empty($ancestors) ) {
|
226 |
$toplevel_ancestor_id = array_pop( $ancestors );
|
227 |
+
$toplevel_ancestor_term = get_term($toplevel_ancestor_id, $term->taxonomy);
|
228 |
+
if ( is_object($toplevel_ancestor_term) && isset($toplevel_ancestor_term->term_order) ) {
|
229 |
+
$front_of_float = (string) $toplevel_ancestor_term->term_order;
|
230 |
+
|
231 |
$rear_of_float = '';
|
232 |
+
$padding = 100; // Make it sort correctly. Not many websites have more than 900 subterms.
|
233 |
foreach ( $ancestors as $ancestor_id ) {
|
234 |
$ancestor_term = get_term($ancestor_id, $term->taxonomy);
|
235 |
if ( is_object($ancestor_term) && isset($ancestor_term->term_order) ) {
|
236 |
+
|
237 |
+
// calculate padding. Too much padding will have deep float calculations go wrong. See https://floating-point-gui.de/basic/
|
238 |
+
$args = array(
|
239 |
+
'orderby' => 'term_order',
|
240 |
+
'order' => 'ASC',
|
241 |
+
'hide_empty' => false,
|
242 |
+
'parent' => $ancestor_id,
|
243 |
+
);
|
244 |
+
$sister_terms = get_term_children( $ancestor_id, $taxonomy );
|
245 |
+
if ( is_array( $sister_terms ) ) { // should always be an array, since this term does exist.
|
246 |
+
$count = count( $sister_terms );
|
247 |
+
if ( $count < 10 ) {
|
248 |
+
$padding = 0;
|
249 |
+
} else if ( $count < 100 ) {
|
250 |
+
$padding = 10;
|
251 |
+
} else if ( $count < 1000 ) {
|
252 |
+
$padding = 100;
|
253 |
+
} else if ( $count < 10000 ) {
|
254 |
+
$padding = 1000;
|
255 |
+
}
|
256 |
+
}
|
257 |
+
$rear_of_float .= (string) ($ancestor_term->term_order + $padding);
|
258 |
}
|
259 |
}
|
260 |
+
|
261 |
+
// calculate padding. Too much padding will have deep float calculations go wrong. See https://floating-point-gui.de/basic/
|
262 |
+
$args = array(
|
263 |
+
'orderby' => 'term_order',
|
264 |
+
'order' => 'ASC',
|
265 |
+
'hide_empty' => false,
|
266 |
+
'parent' => $term->parent,
|
267 |
+
);
|
268 |
+
$sister_terms = get_term_children( $term->parent, $taxonomy );
|
269 |
+
if ( is_array( $sister_terms ) ) { // should always be an array, since this term does exist.
|
270 |
+
$count = count( $sister_terms );
|
271 |
+
if ( $count < 10 ) {
|
272 |
+
$padding = 0;
|
273 |
+
} else if ( $count < 100 ) {
|
274 |
+
$padding = 10;
|
275 |
+
} else if ( $count < 1000 ) {
|
276 |
+
$padding = 100;
|
277 |
+
} else if ( $count < 10000 ) {
|
278 |
+
$padding = 1000;
|
279 |
+
}
|
280 |
+
}
|
281 |
+
$rear_of_float .= (string) ($term->term_order + $padding);
|
282 |
$term->term_order = (float) ( $front_of_float . '.' . $rear_of_float );
|
283 |
}
|
284 |
}
|
285 |
}
|
286 |
}
|
287 |
usort($terms, 'customtax_cmp');
|
|
|
288 |
$terms_new_order = $terms;
|
289 |
/*
|
290 |
* Fires after term array has been ordered with usort.
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: mpol
|
|
3 |
Tags: term order, category order, taxonomy order, order
|
4 |
Requires at least: 3.7
|
5 |
Tested up to: 5.9
|
6 |
-
Stable tag: 3.4.
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
|
@@ -213,6 +213,10 @@ The left metabox lists the toplevel terms. Right (or below) are the sub-terms.
|
|
213 |
|
214 |
== Changelog ==
|
215 |
|
|
|
|
|
|
|
|
|
216 |
= 3.4.0 =
|
217 |
* 2022-03-14
|
218 |
* Support order by post count.
|
3 |
Tags: term order, category order, taxonomy order, order
|
4 |
Requires at least: 3.7
|
5 |
Tested up to: 5.9
|
6 |
+
Stable tag: 3.4.1
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
|
213 |
|
214 |
== Changelog ==
|
215 |
|
216 |
+
= 3.4.1 =
|
217 |
+
* 2022-04-27
|
218 |
+
* Improve ordering nested sub-terms.
|
219 |
+
|
220 |
= 3.4.0 =
|
221 |
* 2022-03-14
|
222 |
* Support order by post count.
|