• I have a CPT with custom hierarchical taxonomy. I need to sort the checklist in the admin panel meta box by the item ID, not the default ‘count’.
    It looks like the list is been generated in wp-admin/includes/template.php and, indeed, if i change ‘count’ to ‘ID’ in line 130, I get the desired result.
    However I would much prefer to work it into my plugin instead of hacking the core. But I do not see any hooks in this file. How do I hook into the wp_terms_checklist()?
    I am sketchy with writing custom hooks so I was hoping to use an existing one. Will someone kindly point me to it or just write me an example code to put in my plugin?
    Thank you in advance.

    • This topic was modified 9 years, 2 months ago by James Huff. Reason: edited topic title to be more descriptive
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The only available hook is the ‘get_terms_orderby’ filter, which is part of the WP_Term_Query class, and used by wp_terms_checklist() several levels down. Your callback is passed the ORDERBY clause, just return whatever version you want to use.

    The problem is you wouldn’t want to alter all queries this way, so you need to selectively add your callback only when needed, then have it remove itself from the call stack when finished. Figure out where wp_terms_checklist() is called where you need to alter its orderby. Locate any action or filter hook before this point. Add the ‘get_terms_orderby’ hook from within a callback added to this earlier hook. It doesn’t matter what it’s really for, as long as it always fires before wp_terms_checklist() is called and does not impact other usage of the WP_Term_Query class.

Viewing 1 replies (of 1 total)

The topic ‘How do I hook into the wp_terms_checklist()?’ is closed to new replies.