Taxonomy Order Not Saving
-
I’m seeing my taxonomies reverting and ignoring the order I’m setting. Is there a specific setting I need in my taxonomy?
-
After investigating the source of the plugin and wp_terms table, I can see that it actually saves the order, but issue comes with filtering get_terms, when plugin try to sort terms and return them in correct order. The issue i that term->term_order it uses is incorrect, the WP fills it with other values, not the ones the plugin expects.
I came up with the following fix. Basically, it does a SQL query to order given term IDs in the proper order.
VER: 3.1.3
FILE: intuitive-custom-post-order.php
LINE: 757; replace 2 lines 757 (“usort…”) and 758 (“return…”) with the following block:// ------------------------------------------------ // PATCH: Fix issue with incorrect term_order // ------------------------------------------------ // usort( $terms, array( $this, 'taxcmp' ) ); // return $terms; // ------------------------------------------------ if (count($terms) < 2) { return $terms; } global $wpdb; $db_result = $wpdb->get_results(" SELECT term_id FROM $wpdb->terms WHERE term_id in (" . join(',', array_map(function ($t) { return $t->term_id; }, $terms)) . ") ORDER BY term_order ", output: ARRAY_N); if (is_array($db_result)) { $ordered_ids = array_map(function ($e) { return intval($e[0]); }, $db_result); $terms_map = []; foreach ($terms as $t) { $terms_map[$t->term_id] = $t; } return array_map(function ($id) use ($terms_map) { return $terms_map[$id]; }, $ordered_ids); } else { usort( $terms, array( $this, 'taxcmp' ) ); return $terms; } // ------------------------------------------------ // END OF PATCH // ------------------------------------------------
@hijiri please take a look at this patch, do your changes and add fix to this awesome plugin. Thank you.
ok
thanks!I confirm the reported problem (for taxonomies for a CPT, both the taxonomy and the CPT created with CPTUI). Not sure about the provided fix. I will follow this thread for an official answer.
- This reply was modified 1 year, 6 months ago by dpacks.
I can confirm this is also an issue. For now we are dragging the posts in alpha order, but for large lists it will be tough.
I also tried the proposed fix, but recieved a php error.
Hoping the plugin author has a fix shortly. Thanks again for the plugin!
Please note, I’ve started seeing this issue with other custom post order plugins. I had this issue with SCPOrder, Real Custom Post Order, and then with this one. Something must have changed in WordPress that causes this, but I can confirm that @greenya’s change does fix the failure to save sorting.
@gishua, if you had a PHP error, then you likely did not replace the code correctly. I commented lines 757 & 758, then added greenya’s code, saved, and reloaded and it worked immediately. I’m glad I found this thread because I would have ended up writing this myself but I’m tired and so grateful to greenya’s help.
@hijiri — update your plugin and you’ll be the only one that works on any of my sites! Please make this minor change and you’ll get dozens of new installs from me 🙂
- The topic ‘Taxonomy Order Not Saving’ is closed to new replies.