• Resolved ksmabe

    (@ksmabe)


    Hi,
    I’m having a trouble in the order of post-tag.

    Problem:
    Sorting post-tag terms in the setting page, the order in get_terms() is correct.
    However, Advanced Custom Field “Taxonomy” in edit-post page and the right column of edit-tags page is not sorted in custom order (but in alphabetical order).

    Other information:
    – I made custom taxonomies, and applied a custom order in the same way, these orders work correctly in ACF or edit-tags page.
    – All the terms are written in Japanese.
    – The tagcloud in edit-tags page is correct order (the same with setting)
    – Auto-Sort queries is Custom Order as defined above.

    I want to arrange tags in admin page too, if possible.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Marcel Pol

    (@mpol)

    Hi,
    The edit-tags page does a database query where the orderby is set hardcoded. You can see it with the plugin Query Monitor. When the query has orderby set to name it won’t overwrite that.

    SELECT t.*, tt.*
    FROM test_terms AS t
    INNER JOIN test_term_taxonomy AS tt
    ON t.term_id = tt.term_id
    WHERE tt.taxonomy IN ('post_tag')
    ORDER BY t.name ASC
    LIMIT 20

    I don’t see a filter for orderby in wp-admin/edit-tags.php or in wp-admin/includes/class-wp-terms-list-table.php
    What does work is adding a parameter to the URL like this:
    /wp-admin/edit-tags.php?taxonomy=post_tag&orderby=term_order

    About ACF terms, I know that each term gets “saved” as a metakey. Looking at the code and the queries I am not sure what is happening. The get_terms query does have an orderby set to t.name. The meta_id’s are ordered by ID. The value of the input field is the term_id however.
    Looking at /advanced-custom-fields/core/fields/taxonomy.php, the function load_value there is a call for wp_get_object_terms that has orderby set to none. That will make the get_terms filter not work.

    I would be interested in feedback :).

    Thread Starter ksmabe

    (@ksmabe)

    I found that the post tag taxonomy is exclude from sorting in custom-taxonomy-order-ne/customtaxorder.php l.288 customtaxorder_wp_get_object_terms_order_filter function.
    I tried commented out that block, order in edit-post page and ACF is as expected (the same with custom order).
    However, javascript errors appeared in the same time.
    So, can you tell me why these taxonomies are excluded in that function?

    Plugin Author Marcel Pol

    (@mpol)

    Ah, thanks for testing that. I thought that was only relevant for the frontend, but apparently it is relevant for admin as well.
    There is a 2.8.2 that only skips that sort when it is on the frontend, not the admin.

    The point of that skipping the sort is that is being run two times through different filters. When the tag_cloud is filtered through the get_terms filter WP Core will resort it and the second run will not be done and there is no sorting applied through this plugin. When I skip the first sort, then WP Core will not touch the sort and will run the second filter (I forgot which) and this plugin will then sort the terms to the set order.
    And yes, it is quite fiddly, this thing :).

    Thread Starter ksmabe

    (@ksmabe)

    Thank you for quick response, @mpol. I greatly appreciate it ??
    I confirmed that post tags are sorted as expected in ACF / edit-tags page with v2.8.2.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sorting post-tag in ACF and edit-post page’ is closed to new replies.