Sub-category order not saving
-
Hi –
My spouse is working on a series of translations of the Bible, and is using the custom order to sort the books in the standard English Bible order. Within each category, however, the books should be in alphanumeric order. I recognize that the set isn’t really designed for this, but we have been able to manually sort the sub-categories into alphanumeric order up until recently.
Now, for whatever reason, the plugin states that the order has been updated, but returns all the terms to the order they were in beforehand.
It only does this on certain books – Deuteronomy, for example – but it is certainly creeping into more places.
Any ideas on what we should do to fix this?
The page I need help with: [log in to see the link]
-
Hi, strange, I haven’t seen that before in this way.
I am not sure what is going on.
Is it possible for you to add this snippet of PHP code to the functions.php of your theme? It should show some debugging information when updating term order.
function my_customtaxorder_update_order( $updated_ids ) { var_dump( $_POST ); } add_action( 'customtaxorder_update_order', 'my_customtaxorder_update_order' );
Then when updating the affected terms, it should show something like:
array(5) { ["custom-taxonomy-order-ne-nonce"]=> string(10) "567145d657" ["order-submit"]=> string(18) "Volgorde bijwerken" ["hidden-custom-order"]=> string(167) "id_1114,id_1115,id_1116,id_1117,id_1118,id_1119,id_1120,id_1121,id_1122,id_1123,id_1124,id_1125,id_1126,id_1127,id_1128,id_1129,id_1130,id_1131,id_1113,id_1132,id_1133" ["hidden-parent-id"]=> string(4) "1082" ["hidden-parent-id-order"]=> string(1) "1" }
If it does show id’s of those terms, it would mean the form on the page is working, but saving to the database is not happening.
Also, the order of the term id’s should be the order in which you did set them. If the order is wrong here, something did go wrong with the form and sending of the list.
Got the script to work – thanks for the debug info!
Here’s what it returns:
array(5) { ["custom-taxonomy-order-ne-nonce"]=> string(10) "aeeb70510f" ["order-submit"]=> string(12) "Update Order" ["hidden-custom-order"]=> string(67) "id_994,id_1178,id_1041,id_804,id_1150,id_1182,id_1185,id_401,id_735" ["hidden-parent-id"]=> string(2) "27" ["hidden-parent-id-order"]=> string(1) "4" }
But the terms return to unordered immediately on the page, and stay unordered on the main page, too!
I should note, we’re using the “alphabetize list” button you provided to order the chapters by number. But even trying to correct by hand hasn’t been working.
Thank you.
This is the order in which it is supposed to be saved, so the form and the JavaScript on it works.I did change some things in the plugin and added a counter to the message for how many terms were really updated.
Could you try the version at:
https://gitlab.com/toomanybicycles/custom-taxonomy-order-ne
It doesn’t fix anything, it will only show how many terms were really tried to be updated in the database. If there are 0, I am still not sure what is going on but it should be 0 in this case ??Also, could you update the custom code in functions.php with:
function my_customtaxorder_update_order( $updated_ids ) { var_dump( $_POST ); echo '<br /><br />'; var_dump( $updated_ids ); } add_action( 'customtaxorder_update_order', 'my_customtaxorder_update_order' );
It should also show the numerical ID’s of the terms that were tried to be updated. Just checking that the
id_994
really does get changed to a numeric value of994
.And another thing, could you check in the database that in the table
wp->terms
there is a columnterm_order
withint( 4 )
andNULL
andDEFAULT '0'
And is it possible to add a line to the file
admin-customtaxorder.php
in current git?
Before line 259, instead ofclean_term_cache( $term_id, $taxonomy );
Could you make it:
var_dump( $result1); var_dump($result2); clean_term_cache( $term_id, $taxonomy );
It should show at least sometimes an
int(1)
meaning that there was a result or sometimes anint(0)
meaning the database update failed or was not needed.And let’s ask yet another question ?? What is the current term_order of category 6?
When you go to
/wp-admin/term.php?taxonomy=bible&tag_ID=1041
what is in the input field? It is supposed to be 2, but since it isn’t being updated, what is it now?
I assume the taxonomy hasbible
as a slug, I hope that is correct.Ok! Sorry for the delay – here’s the data you requested.
1 – New version installed
2 – Returnsarray(5) { ["custom-taxonomy-order-ne-nonce"]=> string(10) "aeeb70510f" ["order-submit"]=> string(12) "Update Order" ["hidden-custom-order"]=> string(67) "id_994,id_1178,id_1041,id_804,id_1150,id_1182,id_1185,id_401,id_735" ["hidden-parent-id"]=> string(2) "27" ["hidden-parent-id-order"]=> string(1) "4" } array(9) { [0]=> int(994) [1]=> int(1178) [2]=> int(1041) [3]=> int(804) [4]=> int(1150) [5]=> int(1182) [6]=> int(1185) [7]=> int(401) [8]=> int(735) }
3 – Yes, the wp->terms database contains a term_order column, and Deut is listed as 4.
4 – Returnsint(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) int(0) array(5) { ["custom-taxonomy-order-ne-nonce"]=> string(10) "b3f72dc2b4" ["order-submit"]=> string(12) "Update Order" ["hidden-custom-order"]=> string(67) "id_994,id_1178,id_1041,id_804,id_1150,id_1182,id_1185,id_401,id_735" ["hidden-parent-id"]=> string(2) "27" ["hidden-parent-id-order"]=> string(1) "4" } array(9) { [0]=> int(994) [1]=> int(1178) [2]=> int(1041) [3]=> int(804) [4]=> int(1150) [5]=> int(1182) [6]=> int(1185) [7]=> int(401) [8]=> int(735) }
I assume this means that the terms are not being updated for some reason.
5 – bible is the slug, yes. Entering that URL takes me to an endless login loop, so I can’t answer your question.Thank you, that was a lot of information requested ??
It all looks correct, code wise. But the database update doesn’t return any rows that were affected, every database request returns 0 rows.
Sorry for that url looping, I thought it would be the correct url.
Could you check for the term_order that is listed for the subterms of Deut, the subterms 4, 5 and 6. They should have term_order listed as 0, 1 and 2.And could you also check the table wp_term_relationships? How many rows do you see for the affected term_taxonomy_id of 1041.
On my test install some terms have multiple rows, some don’t. I do not see how that could happen and I have no clue if this is right or wrong and if it is relevant. Some terms here with multiple rows even had different term_order values.By the way, it might be that you could just workaround this all by editing the term_order on the category edit screen for the affected sub terms.
Aha, ofcourse ??
Thewp_term_relationships
has multiple rows. Theobject_id
is the post ID, so multiple posts can be in the same category. Silly me ??
But still, there should be the same value for term_order as inwp_terms
.Sorry to hijack the thread but i am having the same issue and I believe it is because my term_taxonomy_id and term_id have somehow drifted apart. So this line
UPDATE $wpdb->term_relationships SET term_order = '%d' WHERE term_taxonomy_id ='%d'
…is using the same ID as the following line
UPDATE $wpdb->terms SET term_order = '%d' WHERE term_id ='%d'
and actually that is recording the order against two different taxonomies.
As a “live” example, I have taxonomies (term_ids) in the following order: Apple (1289), Orange (1296), Banana (1278), Grapes (1279). So in the terms table, Orange has an order of 1 and Banana an order of 2.
However the taxonomy_term_ids are different: Apple (1290), Orange (1297), Banana (1279), Grapes (1280)
So in the term_relationships table, everything tagged Orange has an order of 0 while everyhing tagged Banana have the order of 3 instead of 2, because the order is being saved to Grapes term_id.
I hope this makes sense! Not sure if this is OP’s issue as well but it is definitely mine haha.
Edit: I made numerous mistakes in my example ??
Same issue…
Hi,
Thanks for reporting this.I think I got it. This code is 9 years old, and I think the bug is only triggered when
term_id
andterm_taxonomy_id
are different.
I think it is fixed, if my assumptions are correct.Could people please test if this issue is resolved in the current version in gitlab? I would like to hear from you, then it can be released as a new version.
https://gitlab.com/toomanybicycles/custom-taxonomy-order-neWill do, Marcel – thank you for diving into the 9-year-old code! If it works, it’ll make a huge difference for my spouse. ??
That appears to have fixed it! Whoo-hoo! Way to go!
Thank you.
All thanks to Dan Moat who suggested I look at that direction.Tagged as 3.4.4 now.
Argh! So close – it’s working now, sometimes – so we’ve made improvements. But it’s still not working perfectly.
Some of the categories sort alpha/numerically, but in some cases, it throws one or two of the entries to the wrong place – or won’t save the custom order.
But – it works for about 50% of the places, so… improvement!
Hmm, this could be related to an issue that happens with many subcategories. Could that be the case?
With many subcategories, the float variable for sorting becomes less exact and less reliable.
- The topic ‘Sub-category order not saving’ is closed to new replies.