Ranked is broke after post update
-
Hi
Sorry for my english))
I noticed that if I edit a previously added post, sorts in different taxonomies stop working. Post disappears from the records on the site, and also disappears in the plugin itself where their order is set. Post appears again only after clicking “Reset order”
For a long time I could not understand what the problem was, but when studying the Reorder_Post_Within_Categories_Admin class, there is a line in the save_post method$ranked_ids += array_intersect($post_terms, $ranked_terms);
and it doesn’t work properly.
+ = does not add new values to the end of the array, but writes only values for new keys. Old keys do not change
Here is an example.
There are three post taxonomies in which the following terms are selected
(
[0] => 17
[1] => 18
[2] => 19
[3] => 41
)(
[0] => 56
[1] => 24
[2] => 25
[3] => 40
[4] => 29
[5] => 30
[6] => 27
[7] => 31
[8] => 33
[9] => 26
[10] => 37
[11] => 39
[12] => 35
[13] => 38
)(
[0] => 60
[1] => 42
[2] => 45
)at each iteration, the resulting array ($ranked_ids) looks like this:
fitst iteration
[0] => 17
[1] => 18
[2] => 19
[3] => 41secont iteration
[0] => 17
[1] => 18
[2] => 19
[3] => 41
[4] => 29
[5] => 30
[6] => 27
[7] => 31
[8] => 33
[9] => 26
[10] => 37
[11] => 39
[12] => 35
[13] => 38thirt iteration
[0] => 17
[1] => 18
[2] => 19
[3] => 41
[4] => 29
[5] => 30
[6] => 27
[7] => 31
[8] => 33
[9] => 26
[10] => 37
[11] => 39
[12] => 35
[13] => 38Thus 60, 42, 45 and 56,24,25 are absent in the original array, because they were added by old keys that were already filled
In the final array, there are six terms less than needed. So they then lose the post every time the post is updated.You can read more about + = here https://www.php.net/manual/ru/language.operators.array.php
Why you use += ? Is this mistake or not?
- The topic ‘Ranked is broke after post update’ is closed to new replies.