stuttter / wp-term-order

Sort taxonomy terms, your way
https://wordpress.org/plugins/wp-term-order/
GNU General Public License v2.0
95 stars 24 forks source link

Not sticking to new order #17

Closed tmblog closed 2 years ago

tmblog commented 6 years ago

Hi I recently noticed that the customised order reverts back as soon as you leave the page, E.g. I re-order using drag and drop but as soon as I navigate away and back the order reverts back to original. Any reasons why this could be happening? Thanks I am using it for woocommerce product categories by the way.

jimmi-joensson commented 6 years ago

I am currently experiencing the same behavior as @tmblog. The issue happens when I'm trying to put a hierarchical category in the end of the list.

gavin310 commented 5 years ago

Same problem. Sorting works fine until you refresh the page, then it reverts back.

Edit: Seems like what's going on is even after changing the order it defaults back to sorting by the Name column. What I did was just remove sorting by columns from this taxonomy and that seems to work:

add_filter( 'manage_edit-YOURTAXONOMYIDHERE_sortable_columns', function( $sortable_columns ) {
    $sortable_columns = [];
    return $sortable_columns;
} );
richardbuff commented 4 years ago

I had this same problem with WooCommerce under Products > Attributes > configure terms. If you drag and dropped items there, then refreshed, your changes would disappear. The only solution I found was to temporarily disable this plugin, then do the ordering.

Nicscott01 commented 4 years ago

Same issue w/ a custom post type and custom taxonomy. FWIW, there's no spinner that appears like it does in your example GIF after done dragging and dropping. Tried in Safari, FF & Chrome on a Mac. No console errors. I can manually edit the order on the term edit page, however.

Had admin columns plugin running, but shut it off. Same results either way.

JJJ commented 4 years ago

Sorry this is happening. Let's try and figure it out!

What plugins are y'all running?

timiwahalahti commented 3 years ago

I ran into this same issue. Still a bit unsure what is the root cause here, but looks like something is putting name as an orderbyargument for get_terms_orderby hook before this plugin hooks in.

Found out two possible fixes:

Adding 'name' === $args['orderby'] check in https://github.com/stuttter/wp-term-order/blob/b874bc0e70855e2b9f4b88a4b2d2fb2015ecbd6c/wp-term-order.php#L555

OR

Giving higher priority (five seemed to work for me) for the get_terms_orderby filter.

timiwahalahti commented 3 years ago

@JJJ Any updates on this?

JJJ commented 3 years ago

@timiwahalahti sorry, no, but I will try to get to it soon 😰

ronilaukkarinen commented 2 years ago

I think it's reasonable to bump this issue in this point. We are seeing this issue on our sites. Any chance to investigate @JJJ?

JJJ commented 2 years ago

I think perhaps maybe possibly I've corrected this issue in master.

Give it a test, and let me know? 🙏

ronilaukkarinen commented 2 years ago

Thanks, tested it out. Doesn't seem to work yet. It's strange, because admin-ajax request returns 200 OK with a response:

{"next":false,"new_pos":{"8":{"order":1,"parent":0,"depth":0},"23":{"order":2,"parent":0,"depth":0}}}

Console is free of errors.

JJJ commented 2 years ago

@ronilaukkarinen able to provide a list of active plugins, and which taxonomies you're trying this with?

ronilaukkarinen commented 2 years ago

Sure!

Site 1

$ wp plugin list
+------------------------------------+----------+------------------------------+---------+
| name                               | status   | update                       | version |
+------------------------------------+----------+------------------------------+---------+
| acf-content-analysis-for-yoast-seo | active   | none                         | 3.0.1   |
| advanced-custom-fields-pro         | active   | none                         | 5.12.2  |
| air-helper                         | active   | none                         | 2.12.0  |
| force-strong-passwords             | active   | none                         | 1.8.0   |
| gravityforms                       | active   | none                         | 2.6.3   |
| so-clean-up-wp-seo                 | active   | none                         | 3.14.8  |
| imagify                            | active   | none                         | 1.10    |
| insert-headers-and-footers         | active   | none                         | 1.6.2   |
| intuitive-custom-post-order        | active   | none                         | 3.1.3   |
| mailgun                            | active   | none                         | 1.7.9   |
| worker                             | active   | none                         | 4.9.13  |
| polylang-pro                       | active   | none                         | 3.0.6   |
| redis-cache                        | active   | none                         | 2.0.26  |
| simple-history                     | active   | none                         | 3.3.0   |
| wp-sanitize-accented-uploads       | active   | none                         | 1.2     |
| wp-term-order                      | active   | version higher than expected | 1.1.0   |
| wordpress-seo                      | active   | none                         | 19.0    |
| bedrock-autoloader                 | must-use | none                         | 1.0.0   |
| dashboard-widget-upkeep-reminder   | must-use | none                         |         |
| 0-worker                           | must-use | none                         | 1.0.0   |
| object-cache.php                   | dropin   | none                         |         |
+------------------------------------+----------+------------------------------+---------+

Site 2:

$ wp plugin list
+-------------------------------------+----------+-----------+---------+
| name                                | status   | update    | version |
+-------------------------------------+----------+-----------+---------+
| advanced-custom-fields-table-field  | active   | none      | 1.3.14  |
| advanced-custom-fields-pro          | active   | none      | 5.12.2  |
| digitoimistodude-air-helper-c50646b | active   | available | 2.14.1  |
| eventilla                           | active   | none      | 0.1.0   |
| force-strong-passwords              | active   | none      | 1.8.0   |
| gravityforms                        | active   | none      | 2.6.3   |
| so-clean-up-wp-seo                  | active   | none      | 3.14.8  |
| imagify                             | active   | none      | 1.10    |
| intuitive-custom-post-order         | active   | none      | 3.1.3   |
| mailgun                             | active   | none      | 1.7.9   |
| worker                              | active   | none      | 4.9.13  |
| page-for-post-type                  | active   | none      | 0.2.0   |
| redirection                         | active   | none      | 5.2.3   |
| redis-cache                         | active   | none      | 2.0.26  |
| relevanssi-premium                  | active   | none      | 2.18.0  |
| rest-api-for-relevanssi             | active   | none      | 1.15    |
| simple-history                      | active   | none      | 3.3.0   |
| simple-page-ordering                | active   | none      | 2.4.0   |
| wp-sanitize-accented-uploads        | active   | none      | 1.2     |
| wp-term-order                       | active   | none      | 1.0.0   |
| wordpress-seo                       | active   | none      | 19.0    |
| bedrock-autoloader                  | must-use | none      | 1.0.0   |
| dashboard-widget-upkeep-reminder    | must-use | none      |         |
| 0-worker                            | must-use | none      |         |
+-------------------------------------+----------+-----------+---------+

Site 1 has 5 different post types and each has their own taxonomy, here's one example (from cpt registration file):

register_taxonomy('person_category', array( 'person_category' ), array(
  'labels'            => $labels,
  'public'            => false,
  'show_in_nav_menus' => false,
  'show_admin_column' => true,
  'hierarchical'      => true,
  'show_tagcloud'     => false,
  'show_ui'           => true,
  'query_var'         => false,
  'rewrite'           => true,
  'query_var'         => true,
  'capabilities'      => array(),
));

Site 2 has two taxonomies, here's one:

/**
 * Create a taxonomy
 *
 * @uses  Inserts new taxonomy object into the list
 * @uses  Adds query vars
 *
 * @param string  Name of taxonomy object
 * @param array|string  Name of the object type for the taxonomy object.
 * @param array|string  Taxonomy arguments
 * @return null|WP_Error WP_Error if errors, otherwise null.
 */
function obfuscatedsitename_register_tax_person_team() {

  $labels = array(
    'name'                  => _x( 'Tiimit', 'Taxonomy plural name', 'text-domain' ),
    'singular_name'         => _x( 'Tiimi', 'Taxonomy singular name', 'text-domain' ),
    'search_items'          => __( 'Hae tiimejä', 'text-domain' ),
    'popular_items'         => __( 'Suositut tiimit', 'text-domain' ),
    'all_items'             => __( 'Kaikki tiimit', 'text-domain' ),
    'parent_item'           => __( 'Tiimin vanhempi', 'text-domain' ),
    'parent_item_colon'     => __( 'Tiimin vanhempi', 'text-domain' ),
    'edit_item'             => __( 'Muokkaa tiimiä', 'text-domain' ),
    'update_item'           => __( 'Päivitä tiimiä', 'text-domain' ),
    'add_new_item'          => __( 'Lisää uusi tiimi', 'text-domain' ),
    'new_item_name'         => __( 'Uuden tiimin nimi', 'text-domain' ),
    'add_or_remove_items'   => __( 'Lisää tai poista tiimejä', 'text-domain' ),
    'choose_from_most_used' => __( 'Valitse käytetyimmistä tiimeistä', 'text-domain' ),
    'menu_name'             => __( 'Tiimit', 'text-domain' ),
  );

  $args = array(
    'labels'            => $labels,
    'public'            => false,
    'show_in_nav_menus' => false,
    'show_admin_column' => true,
    'hierarchical'      => true,
    'show_tagcloud'     => false,
    'show_ui'           => true,
    'query_var'         => false,
    'rewrite'           => true,
    'query_var'         => true,
    'capabilities'      => array(),
  );

  register_taxonomy( 'person-team', array( 'person' ), $args );
}

add_action( 'init', 'obfuscatedsitename_register_tax_person_team' );

To be clear, it happens with all taxonomies. Even with default article categories (edit-tags.php?taxonomy=category).

timiwahalahti commented 2 years ago

After taking another look into this, found the reason and it's not the plugin working at all as expected 🙈 Or to say, in some situations, the plugin might have compatibility issues that do cause this but other plugins and themes are to blame. Let me try to explain.

We also hook into the get_terms_orderby filter to do something that fixes utf8 ordering (äöå) that does not work in every environment by default. That filter runs before wp-term-order gets to run its filters. That causes the orderby to change in a way that wp-term-order does not recognize it anymore and thus does not set tt.order.

Here's our code. You can see that t.name get's changed. As wp-term-order does run with priority 10, I changed the priority of our filter to 20 and everything works nicely after that.

Because 10 is the default priority, I can imagine also some other cases where similar things happen. So I'd recommend changing the priority for a tad earlier execution.

JJJ commented 2 years ago

I've got this fixed locally, as well as #11 and #3.

Will end up pushing everything simultaneously. Thanks everyone for helping. 🥂