• Resolved yshimizu

    (@yshimizu)


    (I’m using machine translation, so I apologize if this is a strange expression.)

    Sorting child terms of a particular term fails.
    For example, suppose you have the following terms:

    • term A
      • term A-1
      • term A-2
      • term A-3
    • term B
      • term B-1
      • term B-2
      • term B-3
    • term C
      • term C-1
      • term C-2
      • term C-3

    Now, rearrange the child terms of term B from Order Sub-terms as follows and press Update Order.

    • term B-2
    • term B-3
    • term B-1

    Then, after the screen is reloaded, the specified order is broken and displayed as shown below.

    • term B-3
    • term B-1
    • term B-2

    If you press Update Order without rearranging the order, the order will be different from before you pressed the button.

    • term B-2
    • term B-1
    • term B-3

    To make matters worse, this problem doesn’t occur with term A or term C.
    The problem only occurs with child terms of term B.

    The order on the site matches the admin screen, so there is no problem with the code for saving to the database or displaying in the theme file, and I think that the order information changed for some reason when I pressed Update Order.

    Please let me know if there is anything I should check or fix.

    Environment where the problem occurs:

    • WordPress 6.7.2
    • Custom Taxonomy Order 4.0.2

    What I tried to solve the problem:

    • Turn off plugins other than Custom Taxonomy Order
      It didn’t solve the problem. There doesn’t seem to be any interference with other plugins.
    • Change the slug name of the term
      I thought that reserved words, symbols (- and _), number of characters, etc. might be the cause, so I changed it to a shorter one such as “aaa”, but it didn’t solve the problem.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Marcel Pol

    (@mpol)

    Hello yshimizu,

    I followed your workflow, but in my install this works fine. Term B-2, B-3 and B-1 stayed in the same correct order.
    I used the categories from the chessgame-shizzle plugin to test this.

    Which plugin do you use for the terms? And if you use custom code, could you share part of that custom code? Especially the function call for register_post_type and register_taxonomy.

    Regards, Marcel

    Thread Starter yshimizu

    (@yshimizu)

    Thanks for the reply, Marcel.
    I’m not using any plugins and I’m adding custom posts and taxonomies with the following code:

    function custom_post_type__qa(){
    $labels = array(
    'name' => 'よくある質問',
    'menu_name' => 'FAQ',
    'add_new_item' => 'Q&Aを追加',
    'new_item' => '新規Q&A',
    'view_item' => '登録Q&Aを表示',
    'not_found' => '登録Q&Aは見つかりませんでした',
    'not_found_in_trash' => 'ゴミ箱にQ&Aはありません。',
    'search_items' => '登録Q&Aを検索',
    );
    $args = array(
    'labels' => $labels,
    'public' => false,
    'show_ui' => true,
    'hierarchical' => false,
    'exclude_from_search' => false,
    'has_archive' => false,
    'show_in_rest' => false,
    'supports' => array('title','editor','revisions'),
    'rewrite' => array(
    'with_front' => false
    ),
    'menu_icon' => 'dashicons-editor-help',
    'map_meta_cap' => true
    );
    register_post_type( 'qa' , $args);
    }
    add_action('init', 'custom_post_type__qa' );
    register_taxonomy(
    'qa_category',
    'qa',
    array(
    'rewrite' => array('slug' => 'category'),
    'label' => 'Q&Aカテゴリー',
    'labels' => array(
    'menu_name' => 'Q&Aカテゴリー',
    'add_new_item'=> '新規Q&Aカテゴリーを追加',
    ),
    'public' => true,
    'show_ui' => true,
    'hierarchical' => true,
    'has_archive' => true,
    'query_var' => true,
    'show_admin_column' => true,
    'show_in_rest' => false,
    )
    );

    After that, I paid close attention to how term_order was updated in the database for the problematic terms, and at what point the specified order became strange.

    After rearranging the child terms, the moment I clicked Update Order, the specified order was maintained.

    The term_order values ??in the database were also in the specified order, and the number of terms whose order had been updated, displayed in the message “Order of X terms updated,” was correct.

    From this, it seems that the updated term_order order is not reflected on the updated screen.

    In addition, this taxonomy has quite a large number of terms, with 14 parent terms and 47 child terms.
    Could this be related?

    Plugin Author Marcel Pol

    (@mpol)

    I’m sorry, I still don’t see the same as you do.

    I don’t think the number of terms should have any influence. On the admin side it is simply an integer that is used for sorting.

    The attached code, the register_taxonomy is pasted outside the action hook. Are you sure that is correct? The functioncall should be inside the init hook.

    If you check in the inspector you can also see the term order in the html, like:

    <li id="id_1277" data-slug="b-2" data-term-order="0" class="lineitem ui-sortable-handle">B-2<br>
    <span style="color:#aaa">(b-2)</span>
    </li>

    Do the data-term-order numbers go up here as well?

    Thread Starter yshimizu

    (@yshimizu)

    I placed the register_taxonomy action hook in the init hook, but there was no change.

    The data-term-order value did not change before or after I clicked Update Order.

    The data-term-order values ??of the parent terms were 1, 2, 3…, and the child terms had the same value as the parent terms.

    For example, if the data-term-order of parent term B is 2, the data-term-order of child terms B-1, B-2, B-3 will be 2 (I think this is by design).

    I finally solved the problem by disabling this plugin, temporarily updating the sorting order using another sorting plugin, and then re-enabling this plugin.
    It’s working fine now, so maybe some process was stumbling somewhere…

    Thanks for putting up with this problem, Marcel.
    I’ll post again if I can confirm that it’s reproducible (or if I find the direct cause).

    Plugin Author Marcel Pol

    (@mpol)

    Hi, that is strange.

    With the sub-terms, they are ordered 0, 1 and 2 (B-2, B-3 an B-1).

    Glad you solved it.
    I was starting to think there might have been a JavaScript error, but apparently not.

    I had the same problem. Test site worked fine. Live site, drag and drop did not work. No JS error, no PHP error, the POST request was correct and returned 200.

    Adding a term ‘Temporary’ and it work. Remove term ‘Temporary’ and it stopped working.

    Set term order using the ‘order’ field on each term worked.

    Conflict with Simple Custom Post Order plugin is possible but I don’t see why. The plugin is also on the test site. On the live site only one of my sets of sub-terms fails drag-and-drop reordering.

    That other plugin is used to order posts, and can order taxnonomy terms but does not work reliably for ordering sub-terms, so both plugins are in use. The idea that it is relevant is pure guesswork.

    I have the impression that when drag-and-drop ordering fails, the items with a single-digit order integer are correctly ordered.

    • This reply was modified 2 weeks, 2 days ago by John_W_B.
    • This reply was modified 2 weeks, 2 days ago by John_W_B.

    The probem arises when at least one of the term_order fields has double digits, and does not seem to arise when it has only single digits. The drag and drop tends to update the order using double digits even where the number of terms is < 10. Therefore I think that the problem is that get_terms() in page-customtaxorder.php is sorting alphabetically, at least is not sorting integers numerically. See https://wordpress.stackexchange.com/questions/80063/get-terms-orderby-name-as-numbers

    However, I cannot explain why the problem seems to be intermittent.

    • This reply was modified 2 weeks, 2 days ago by John_W_B.
    Plugin Author Marcel Pol

    (@mpol)

    Hello,

    Could you check in your database, with the wp_terms table. Is term_order an int(4) type?

    Regards, Marcel

    Hello Michael

    Yes I just checked the db and wp_order column is int(4).

    Plugin Author Marcel Pol

    (@mpol)

    I suppose you mean term_order column in wp_terms table? ??

    I really have no clue then, sorry.

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.